clear all

log using "/Users/Didac/Dropbox/Shared/Replication Files/IO_Replication/Data_building_part_2_print.smcl", replace

* Set the Path
cd "/Users/Didac/Dropbox/Shared/Replication Files/IO_Replication/"

*********************************************************************
* COMPUTER WAR IN ADJACENT COUNTRIES
* Exclude war between i and -i. 
*********************************************************************

use "war_default_dataset_participants.dta", clear
gen	Albania_neighbor  = 1 if country == "Greece" | country == "Kosovo" | country == "Macedonia" | country == "Montenegro" 
replace external_war = 0 if participants_inter1 == "Albania"
replace external_war = 0 if participants_inter2 == "Albania"
replace external_war = 0 if participants_inter3 == "Albania"
replace external_war = 0 if participants_inter4 == "Albania"
replace external_war = 0 if participants_inter5 == "Albania"
replace external_war = 0 if participants_inter6 == "Albania"
replace external_war = 0 if participants_inter7 == "Albania"
replace external_war = 0 if participants_inter8 == "Albania"
replace external_war = 0 if participants_inter9 == "Albania"
replace external_war = 0 if participants_inter10 == "Albania"
replace external_war = 0 if participants_inter11 == "Albania"
replace external_war = 0 if participants_inter12 =="Albania"
bysort year: egen tool = total(external_war) if Albania_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Albania"
drop tool external_war participant* Albania_neighbor
save "_Albania_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Argentina_neighbor  = 1 if country == "Bolivia" | country == "Brazil" | country == "Chile" | country == "Paraguay" | country == "Uruguay" 
replace external_war = 0 if participants_inter1 == "Argentina"
replace external_war = 0 if participants_inter2 == "Argentina"
replace external_war = 0 if participants_inter3 == "Argentina"
replace external_war = 0 if participants_inter4 == "Argentina"
replace external_war = 0 if participants_inter5 == "Argentina"
replace external_war = 0 if participants_inter6 == "Argentina"
replace external_war = 0 if participants_inter7 == "Argentina"
replace external_war = 0 if participants_inter8 == "Argentina"
replace external_war = 0 if participants_inter9 == "Argentina"
replace external_war = 0 if participants_inter10 == "Argentina"
replace external_war = 0 if participants_inter11 == "Argentina"
replace external_war = 0 if participants_inter12 =="Argentina"
bysort year: egen tool = total(external_war) if Argentina_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Argentina"
drop tool external_war participant* Argentina_neighbor
save "_Argentina_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Armenia_neighbor  = 1 if country == "Azerbaijan" | country == "Georgia" | country == "Iran" | country == "Turkey" 
replace external_war = 0 if participants_inter1 == "Armenia"
replace external_war = 0 if participants_inter2 == "Armenia"
replace external_war = 0 if participants_inter3 == "Armenia"
replace external_war = 0 if participants_inter4 == "Armenia"
replace external_war = 0 if participants_inter5 == "Armenia"
replace external_war = 0 if participants_inter6 == "Armenia"
replace external_war = 0 if participants_inter7 == "Armenia"
replace external_war = 0 if participants_inter8 == "Armenia"
replace external_war = 0 if participants_inter9 == "Armenia"
replace external_war = 0 if participants_inter10 == "Armenia"
replace external_war = 0 if participants_inter11 == "Armenia"
replace external_war = 0 if participants_inter12 =="Armenia"
bysort year: egen tool = total(external_war) if Armenia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Armenia"
drop tool external_war participant* Armenia_neighbor
save "_Armenia_neighbors.dta", replace




use "war_default_dataset_participants.dta", clear
gen	Australia_neighbor  = 1 if country == "New Zealand"
replace external_war = 0 if participants_inter1 == "Australia"
replace external_war = 0 if participants_inter2 == "Australia"
replace external_war = 0 if participants_inter3 == "Australia"
replace external_war = 0 if participants_inter4 == "Australia"
replace external_war = 0 if participants_inter5 == "Australia"
replace external_war = 0 if participants_inter6 == "Australia"
replace external_war = 0 if participants_inter7 == "Australia"
replace external_war = 0 if participants_inter8 == "Australia"
replace external_war = 0 if participants_inter9 == "Australia"
replace external_war = 0 if participants_inter10 == "Australia"
replace external_war = 0 if participants_inter11 == "Australia"
replace external_war = 0 if participants_inter12 =="Australia"
bysort year: egen tool = total(external_war) if Australia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Australia"
drop tool external_war participant* Australia_neighbor
save "_Australia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Austria_neighbor  = 1 if country == "Czech Republic" | country == "Germany" | country == "Hungary" | country == "Italy" | country == "Liechtenstein" | country == "Slovakia" | country == "Slovenia" | country == "Switzerland" 
replace external_war = 0 if participants_inter1 == "Austria"
replace external_war = 0 if participants_inter2 == "Austria"
replace external_war = 0 if participants_inter3 == "Austria"
replace external_war = 0 if participants_inter4 == "Austria"
replace external_war = 0 if participants_inter5 == "Austria"
replace external_war = 0 if participants_inter6 == "Austria"
replace external_war = 0 if participants_inter7 == "Austria"
replace external_war = 0 if participants_inter8 == "Austria"
replace external_war = 0 if participants_inter9 == "Austria"
replace external_war = 0 if participants_inter10 == "Austria"
replace external_war = 0 if participants_inter11 == "Austria"
replace external_war = 0 if participants_inter12 =="Austria"
bysort year: egen tool = total(external_war) if Austria_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Austria"
drop tool external_war participant* Austria_neighbor
save "_Austria_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Azerbaijan_neighbor  = 1 if country == "Armenia" | country == "Georgia" | country == "Iran" | country == "Russia" | country == "Turkey" 
replace external_war = 0 if participants_inter1 == "Azerbaijan"
replace external_war = 0 if participants_inter2 == "Azerbaijan"
replace external_war = 0 if participants_inter3 == "Azerbaijan"
replace external_war = 0 if participants_inter4 == "Azerbaijan"
replace external_war = 0 if participants_inter5 == "Azerbaijan"
replace external_war = 0 if participants_inter6 == "Azerbaijan"
replace external_war = 0 if participants_inter7 == "Azerbaijan"
replace external_war = 0 if participants_inter8 == "Azerbaijan"
replace external_war = 0 if participants_inter9 == "Azerbaijan"
replace external_war = 0 if participants_inter10 == "Azerbaijan"
replace external_war = 0 if participants_inter11 == "Azerbaijan"
replace external_war = 0 if participants_inter12 =="Azerbaijan"
bysort year: egen tool = total(external_war) if Azerbaijan_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Azerbaijan"
drop tool external_war participant* Azerbaijan_neighbor
save "_Azerbaijan_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Bangladesh_neighbor  = 1 if country == "India" | country == "Myanmar" 
replace external_war = 0 if participants_inter1 == "Bangladesh"
replace external_war = 0 if participants_inter2 == "Bangladesh"
replace external_war = 0 if participants_inter3 == "Bangladesh"
replace external_war = 0 if participants_inter4 == "Bangladesh"
replace external_war = 0 if participants_inter5 == "Bangladesh"
replace external_war = 0 if participants_inter6 == "Bangladesh"
replace external_war = 0 if participants_inter7 == "Bangladesh"
replace external_war = 0 if participants_inter8 == "Bangladesh"
replace external_war = 0 if participants_inter9 == "Bangladesh"
replace external_war = 0 if participants_inter10 == "Bangladesh"
replace external_war = 0 if participants_inter11 == "Bangladesh"
replace external_war = 0 if participants_inter12 =="Bangladesh"
bysort year: egen tool = total(external_war) if Bangladesh_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Bangladesh"
drop tool external_war participant* Bangladesh_neighbor
save "_Bangladesh_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Belarus_neighbor  = 1 if country == "Latvia" | country == "Lithuania" | country == "Poland" | country == "Russia" | country == "Ukraine" 
replace external_war = 0 if participants_inter1 == "Belarus"
replace external_war = 0 if participants_inter2 == "Belarus"
replace external_war = 0 if participants_inter3 == "Belarus"
replace external_war = 0 if participants_inter4 == "Belarus"
replace external_war = 0 if participants_inter5 == "Belarus"
replace external_war = 0 if participants_inter6 == "Belarus"
replace external_war = 0 if participants_inter7 == "Belarus"
replace external_war = 0 if participants_inter8 == "Belarus"
replace external_war = 0 if participants_inter9 == "Belarus"
replace external_war = 0 if participants_inter10 == "Belarus"
replace external_war = 0 if participants_inter11 == "Belarus"
replace external_war = 0 if participants_inter12 =="Belarus"
bysort year: egen tool = total(external_war) if Belarus_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Belarus"
drop tool external_war participant* Belarus_neighbor
save "_Belarus_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Belgium_neighbor  = 1 if country == "France" | country == "Germany" | country == "Luxembourg" | country == "Netherlands" 
replace external_war = 0 if participants_inter1 == "Belgium"
replace external_war = 0 if participants_inter2 == "Belgium"
replace external_war = 0 if participants_inter3 == "Belgium"
replace external_war = 0 if participants_inter4 == "Belgium"
replace external_war = 0 if participants_inter5 == "Belgium"
replace external_war = 0 if participants_inter6 == "Belgium"
replace external_war = 0 if participants_inter7 == "Belgium"
replace external_war = 0 if participants_inter8 == "Belgium"
replace external_war = 0 if participants_inter9 == "Belgium"
replace external_war = 0 if participants_inter10 == "Belgium"
replace external_war = 0 if participants_inter11 == "Belgium"
replace external_war = 0 if participants_inter12 =="Belgium"
bysort year: egen tool = total(external_war) if Belgium_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Belgium"
drop tool external_war participant* Belgium_neighbor
save "_Belgium_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Bhutan_neighbor  = 1 if country == "China" | country == "India" 
replace external_war = 0 if participants_inter1 == "Bhutan"
replace external_war = 0 if participants_inter2 == "Bhutan"
replace external_war = 0 if participants_inter3 == "Bhutan"
replace external_war = 0 if participants_inter4 == "Bhutan"
replace external_war = 0 if participants_inter5 == "Bhutan"
replace external_war = 0 if participants_inter6 == "Bhutan"
replace external_war = 0 if participants_inter7 == "Bhutan"
replace external_war = 0 if participants_inter8 == "Bhutan"
replace external_war = 0 if participants_inter9 == "Bhutan"
replace external_war = 0 if participants_inter10 == "Bhutan"
replace external_war = 0 if participants_inter11 == "Bhutan"
replace external_war = 0 if participants_inter12 =="Bhutan"
bysort year: egen tool = total(external_war) if Bhutan_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Bhutan"
drop tool external_war participant* Bhutan_neighbor
save "_Bhutan_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Bolivia_neighbor  = 1 if country == "Argentina" | country == "Brazil" | country == "Chile" | country == "Paraguay" | country == "Peru" 
replace external_war = 0 if participants_inter1 == "Bolivia"
replace external_war = 0 if participants_inter2 == "Bolivia"
replace external_war = 0 if participants_inter3 == "Bolivia"
replace external_war = 0 if participants_inter4 == "Bolivia"
replace external_war = 0 if participants_inter5 == "Bolivia"
replace external_war = 0 if participants_inter6 == "Bolivia"
replace external_war = 0 if participants_inter7 == "Bolivia"
replace external_war = 0 if participants_inter8 == "Bolivia"
replace external_war = 0 if participants_inter9 == "Bolivia"
replace external_war = 0 if participants_inter10 == "Bolivia"
replace external_war = 0 if participants_inter11 == "Bolivia"
replace external_war = 0 if participants_inter12 =="Bolivia"
bysort year: egen tool = total(external_war) if Bolivia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Bolivia"
drop tool external_war participant* Bolivia_neighbor
save "_Bolivia_neighbors.dta", replace

use "war_default_dataset_participants.dta", clear
gen	Bosnia_and_Herzegovina_neighbor  = 1 if country == "Croatia" | country == "Montenegro" | country == "Serbia" 
replace external_war = 0 if participants_inter1 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter2 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter3 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter4 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter5 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter6 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter7 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter8 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter9 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter10 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter11 == "Bosnia and Herzegovina"
replace external_war = 0 if participants_inter12 =="Bosnia and Herzegovina"
bysort year: egen tool = total(external_war) if Bosnia_and_Herzegovina_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Bosnia and Herzegovina"
drop tool external_war participant* Bosnia_and_Herzegovina_neighbor
save "_Bosnia_and_Herzegovina_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Brazil_neighbor  = 1 if country == "Argentina" | country == "Bolivia" | country == "Colombia" | country == "FrenchGuiana" | country == "Guyana" | country == "Paraguay" | country == "Peru" | country == "Suriname" | country == "Uruguay" | country == "Venezuela"
replace external_war = 0 if participants_inter1 == "Brazil"
replace external_war = 0 if participants_inter2 == "Brazil"
replace external_war = 0 if participants_inter3 == "Brazil"
replace external_war = 0 if participants_inter4 == "Brazil"
replace external_war = 0 if participants_inter5 == "Brazil"
replace external_war = 0 if participants_inter6 == "Brazil"
replace external_war = 0 if participants_inter7 == "Brazil"
replace external_war = 0 if participants_inter8 == "Brazil"
replace external_war = 0 if participants_inter9 == "Brazil"
replace external_war = 0 if participants_inter10 == "Brazil"
replace external_war = 0 if participants_inter11 == "Brazil"
replace external_war = 0 if participants_inter12 =="Brazil"
bysort year: egen tool = total(external_war) if Brazil_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Brazil"
drop tool external_war participant* Brazil_neighbor
sort year
save "_Brazil_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Bulgaria_neighbor  = 1 if country == "Greece" | country == "Macedonia" | country == "Romania" | country == "Serbia" | country == "Turkey" 
replace external_war = 0 if participants_inter1 == "Bulgaria"
replace external_war = 0 if participants_inter2 == "Bulgaria"
replace external_war = 0 if participants_inter3 == "Bulgaria"
replace external_war = 0 if participants_inter4 == "Bulgaria"
replace external_war = 0 if participants_inter5 == "Bulgaria"
replace external_war = 0 if participants_inter6 == "Bulgaria"
replace external_war = 0 if participants_inter7 == "Bulgaria"
replace external_war = 0 if participants_inter8 == "Bulgaria"
replace external_war = 0 if participants_inter9 == "Bulgaria"
replace external_war = 0 if participants_inter10 == "Bulgaria"
replace external_war = 0 if participants_inter11 == "Bulgaria"
replace external_war = 0 if participants_inter12 =="Bulgaria"
bysort year: egen tool = total(external_war) if Bulgaria_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Bulgaria"
drop tool external_war participant* Bulgaria_neighbor
save "_Bulgaria_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Burundi_neighbor  = 1 if country == "Democratic Republic of the Congo" | country == "Rwanda" | country == "Tanzania" 
replace external_war = 0 if participants_inter1 == "Burundi"
replace external_war = 0 if participants_inter2 == "Burundi"
replace external_war = 0 if participants_inter3 == "Burundi"
replace external_war = 0 if participants_inter4 == "Burundi"
replace external_war = 0 if participants_inter5 == "Burundi"
replace external_war = 0 if participants_inter6 == "Burundi"
replace external_war = 0 if participants_inter7 == "Burundi"
replace external_war = 0 if participants_inter8 == "Burundi"
replace external_war = 0 if participants_inter9 == "Burundi"
replace external_war = 0 if participants_inter10 == "Burundi"
replace external_war = 0 if participants_inter11 == "Burundi"
replace external_war = 0 if participants_inter12 =="Burundi"
bysort year: egen tool = total(external_war) if Burundi_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Burundi"
drop tool external_war participant* Burundi_neighbor
save "_Burundi_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Cambodia_neighbor  = 1 if country == "Laos" | country == "Thailand" | country == "Vietnam" 
replace external_war = 0 if participants_inter1 == "Cambodia"
replace external_war = 0 if participants_inter2 == "Cambodia"
replace external_war = 0 if participants_inter3 == "Cambodia"
replace external_war = 0 if participants_inter4 == "Cambodia"
replace external_war = 0 if participants_inter5 == "Cambodia"
replace external_war = 0 if participants_inter6 == "Cambodia"
replace external_war = 0 if participants_inter7 == "Cambodia"
replace external_war = 0 if participants_inter8 == "Cambodia"
replace external_war = 0 if participants_inter9 == "Cambodia"
replace external_war = 0 if participants_inter10 == "Cambodia"
replace external_war = 0 if participants_inter11 == "Cambodia"
replace external_war = 0 if participants_inter12 =="Cambodia"
bysort year: egen tool = total(external_war) if Cambodia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Cambodia"
drop tool external_war participant* Cambodia_neighbor
save "_Cambodia_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Canada_neighbor  = 1 if country == "United States of America" 
replace external_war = 0 if participants_inter1 == "Canada"
replace external_war = 0 if participants_inter2 == "Canada"
replace external_war = 0 if participants_inter3 == "Canada"
replace external_war = 0 if participants_inter4 == "Canada"
replace external_war = 0 if participants_inter5 == "Canada"
replace external_war = 0 if participants_inter6 == "Canada"
replace external_war = 0 if participants_inter7 == "Canada"
replace external_war = 0 if participants_inter8 == "Canada"
replace external_war = 0 if participants_inter9 == "Canada"
replace external_war = 0 if participants_inter10 == "Canada"
replace external_war = 0 if participants_inter11 == "Canada"
replace external_war = 0 if participants_inter12 =="Canada"
bysort year: egen tool = total(external_war) if Canada_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Canada"
drop tool external_war participant* Canada_neighbor
save "_Canada_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Chad_neighbor  = 1 if country == "Cameroon" | country == "Central African Republic" | country == "Libya" | country == "Niger" | country == "Nigeria" | country == "Sudan" 
replace external_war = 0 if participants_inter1 == "Chad"
replace external_war = 0 if participants_inter2 == "Chad"
replace external_war = 0 if participants_inter3 == "Chad"
replace external_war = 0 if participants_inter4 == "Chad"
replace external_war = 0 if participants_inter5 == "Chad"
replace external_war = 0 if participants_inter6 == "Chad"
replace external_war = 0 if participants_inter7 == "Chad"
replace external_war = 0 if participants_inter8 == "Chad"
replace external_war = 0 if participants_inter9 == "Chad"
replace external_war = 0 if participants_inter10 == "Chad"
replace external_war = 0 if participants_inter11 == "Chad"
replace external_war = 0 if participants_inter12 =="Chad"
bysort year: egen tool = total(external_war) if Chad_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Chad"
drop tool external_war participant* Chad_neighbor
save "_Chad_neighbors.dta", replace

use "war_default_dataset_participants.dta", clear
gen	Chile_neighbor  = 1 if country == "Argentina" | country == "Bolivia" | country == "Peru" 
replace external_war = 0 if participants_inter1 == "Chile"
replace external_war = 0 if participants_inter2 == "Chile"
replace external_war = 0 if participants_inter3 == "Chile"
replace external_war = 0 if participants_inter4 == "Chile"
replace external_war = 0 if participants_inter5 == "Chile"
replace external_war = 0 if participants_inter6 == "Chile"
replace external_war = 0 if participants_inter7 == "Chile"
replace external_war = 0 if participants_inter8 == "Chile"
replace external_war = 0 if participants_inter9 == "Chile"
replace external_war = 0 if participants_inter10 == "Chile"
replace external_war = 0 if participants_inter11 == "Chile"
replace external_war = 0 if participants_inter12 =="Chile"
bysort year: egen tool = total(external_war) if Chile_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Chile"
drop tool external_war participant* Chile_neighbor
save "_Chile_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	China_neighbor  = 1 if country == "Afghanistan" | country == "Bhutan" | country == "Hong Kong" | country == "India" | country == "Kazakhstan" | country == "Kyrgyzstan" | country == "Laos" | country == "Macau" | country == "Mongolia" | country == "Myanmar" | country == "Nepal" |  	country == "North Korea" |  	country == "Pakistan" |  	country == "Russia" |  	country == "Tajikistan" |  	country == "Vietnam"  
replace external_war = 0 if participants_inter1 == "China"
replace external_war = 0 if participants_inter2 == "China"
replace external_war = 0 if participants_inter3 == "China"
replace external_war = 0 if participants_inter4 == "China"
replace external_war = 0 if participants_inter5 == "China"
replace external_war = 0 if participants_inter6 == "China"
replace external_war = 0 if participants_inter7 == "China"
replace external_war = 0 if participants_inter8 == "China"
replace external_war = 0 if participants_inter9 == "China"
replace external_war = 0 if participants_inter10 == "China"
replace external_war = 0 if participants_inter11 == "China"
replace external_war = 0 if participants_inter12 =="China"
bysort year: egen tool = total(external_war) if China_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "China"
drop tool external_war participant* China_neighbor
save "_China_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Colombia_neighbor  = 1 if country == "Brazil" | country == "Ecuador" | country == "Panama" | country == "Peru" | country == "Venezuela" 
replace external_war = 0 if participants_inter1 == "Colombia"
replace external_war = 0 if participants_inter2 == "Colombia"
replace external_war = 0 if participants_inter3 == "Colombia"
replace external_war = 0 if participants_inter4 == "Colombia"
replace external_war = 0 if participants_inter5 == "Colombia"
replace external_war = 0 if participants_inter6 == "Colombia"
replace external_war = 0 if participants_inter7 == "Colombia"
replace external_war = 0 if participants_inter8 == "Colombia"
replace external_war = 0 if participants_inter9 == "Colombia"
replace external_war = 0 if participants_inter10 == "Colombia"
replace external_war = 0 if participants_inter11 == "Colombia"
replace external_war = 0 if participants_inter12 =="Colombia"
bysort year: egen tool = total(external_war) if Colombia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Colombia"
drop tool external_war participant* Colombia_neighbor
save "_Colombia_neighbors.dta", replace

use "war_default_dataset_participants.dta", clear
gen	Congo_neighbor  = 1 if country == "Angola" | country == "Cameroon" | country == "Central African Republic" | country == "Democratic Republic of the Congo" | country == "Gabon" 
replace external_war = 0 if participants_inter1 == "Congo"
replace external_war = 0 if participants_inter2 == "Congo"
replace external_war = 0 if participants_inter3 == "Congo"
replace external_war = 0 if participants_inter4 == "Congo"
replace external_war = 0 if participants_inter5 == "Congo"
replace external_war = 0 if participants_inter6 == "Congo"
replace external_war = 0 if participants_inter7 == "Congo"
replace external_war = 0 if participants_inter8 == "Congo"
replace external_war = 0 if participants_inter9 == "Congo"
replace external_war = 0 if participants_inter10 == "Congo"
replace external_war = 0 if participants_inter11 == "Congo"
replace external_war = 0 if participants_inter12 =="Congo"
bysort year: egen tool = total(external_war) if Congo_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Congo"
drop tool external_war participant* Congo_neighbor
save "_Congo_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Costa_Rica_neighbor  = 1 if country == "Nicaragua" | country == "Panama" 
replace external_war = 0 if participants_inter1 == "Costa Rica"
replace external_war = 0 if participants_inter2 == "Costa Rica"
replace external_war = 0 if participants_inter3 == "Costa Rica"
replace external_war = 0 if participants_inter4 == "Costa Rica"
replace external_war = 0 if participants_inter5 == "Costa Rica"
replace external_war = 0 if participants_inter6 == "Costa Rica"
replace external_war = 0 if participants_inter7 == "Costa Rica"
replace external_war = 0 if participants_inter8 == "Costa Rica"
replace external_war = 0 if participants_inter9 == "Costa Rica"
replace external_war = 0 if participants_inter10 == "Costa Rica"
replace external_war = 0 if participants_inter11 == "Costa Rica"
replace external_war = 0 if participants_inter12 =="Costa Rica"
bysort year: egen tool = total(external_war) if Costa_Rica_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Costa Rica"
drop tool external_war participant* Costa_Rica_neighbor
save "_Costa_Rica_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Croatia_neighbor  = 1 if country == "Bosnia and Herzegovina" | country == "Hungary" | country == "Montenegro" | country == "Serbia" | country == "Slovenia" 
replace external_war = 0 if participants_inter1 == "Croatia"
replace external_war = 0 if participants_inter2 == "Croatia"
replace external_war = 0 if participants_inter3 == "Croatia"
replace external_war = 0 if participants_inter4 == "Croatia"
replace external_war = 0 if participants_inter5 == "Croatia"
replace external_war = 0 if participants_inter6 == "Croatia"
replace external_war = 0 if participants_inter7 == "Croatia"
replace external_war = 0 if participants_inter8 == "Croatia"
replace external_war = 0 if participants_inter9 == "Croatia"
replace external_war = 0 if participants_inter10 == "Croatia"
replace external_war = 0 if participants_inter11 == "Croatia"
replace external_war = 0 if participants_inter12 =="Croatia"
bysort year: egen tool = total(external_war) if Croatia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Croatia"
drop tool external_war participant* Croatia_neighbor
save "_Croatia_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Cyprus_neighbor  = 1 if country == "Turkey" 
replace external_war = 0 if participants_inter1 == "Cyprus"
replace external_war = 0 if participants_inter2 == "Cyprus"
replace external_war = 0 if participants_inter3 == "Cyprus"
replace external_war = 0 if participants_inter4 == "Cyprus"
replace external_war = 0 if participants_inter5 == "Cyprus"
replace external_war = 0 if participants_inter6 == "Cyprus"
replace external_war = 0 if participants_inter7 == "Cyprus"
replace external_war = 0 if participants_inter8 == "Cyprus"
replace external_war = 0 if participants_inter9 == "Cyprus"
replace external_war = 0 if participants_inter10 == "Cyprus"
replace external_war = 0 if participants_inter11 == "Cyprus"
replace external_war = 0 if participants_inter12 =="Cyprus"
bysort year: egen tool = total(external_war) if Cyprus_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Cyprus"
drop tool external_war participant* Cyprus_neighbor
save "_Cyprus_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Czech_Republic_neighbor  = 1 if country == "Austria" | country == "Germany" | country == "Poland" | country == "Slovakia" 
replace external_war = 0 if participants_inter1 == "Czech Republic"
replace external_war = 0 if participants_inter2 == "Czech Republic"
replace external_war = 0 if participants_inter3 == "Czech Republic"
replace external_war = 0 if participants_inter4 == "Czech Republic"
replace external_war = 0 if participants_inter5 == "Czech Republic"
replace external_war = 0 if participants_inter6 == "Czech Republic"
replace external_war = 0 if participants_inter7 == "Czech Republic"
replace external_war = 0 if participants_inter8 == "Czech Republic"
replace external_war = 0 if participants_inter9 == "Czech Republic"
replace external_war = 0 if participants_inter10 == "Czech Republic"
replace external_war = 0 if participants_inter11 == "Czech Republic"
replace external_war = 0 if participants_inter12 =="Czech Republic"
bysort year: egen tool = total(external_war) if Czech_Republic_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Czech Republic"
drop tool external_war participant* Czech_Republic_neighbor
save "_Czech_Republic_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	DR_Congo_neighbor  = 1 if country == "Angola" | country == "Burundi" | country == "Central African Republic" | country == "Congo" | country == "Rwanda" | country == "South Sudan" | country == "Tanzania" | country == "Uganda" | country == "Zambia" 
replace external_war = 0 if participants_inter1 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter2 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter3 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter4 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter5 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter6 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter7 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter8 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter9 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter10 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter11 == "Democratic Republic of the Congo"
replace external_war = 0 if participants_inter12 =="Democratic Republic of the Congo"
bysort year: egen tool = total(external_war) if DR_Congo_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Democratic Republic of the Congo"
drop tool external_war participant* DR_Congo_neighbor
save "_Democratic_Republic_Congo_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Denmark_neighbor  = 1 if country == "Germany" 
replace external_war = 0 if participants_inter1 == "Denmark"
replace external_war = 0 if participants_inter2 == "Denmark"
replace external_war = 0 if participants_inter3 == "Denmark"
replace external_war = 0 if participants_inter4 == "Denmark"
replace external_war = 0 if participants_inter5 == "Denmark"
replace external_war = 0 if participants_inter6 == "Denmark"
replace external_war = 0 if participants_inter7 == "Denmark"
replace external_war = 0 if participants_inter8 == "Denmark"
replace external_war = 0 if participants_inter9 == "Denmark"
replace external_war = 0 if participants_inter10 == "Denmark"
replace external_war = 0 if participants_inter11 == "Denmark"
replace external_war = 0 if participants_inter12 =="Denmark"
bysort year: egen tool = total(external_war) if Denmark_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Denmark"
drop tool external_war participant* Denmark_neighbor
save "_Denmark_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Dominican_Republic_neighbor  = 1 if country == "Haiti" 
replace external_war = 0 if participants_inter1 == "Dominican Republic"
replace external_war = 0 if participants_inter2 == "Dominican Republic"
replace external_war = 0 if participants_inter3 == "Dominican Republic"
replace external_war = 0 if participants_inter4 == "Dominican Republic"
replace external_war = 0 if participants_inter5 == "Dominican Republic"
replace external_war = 0 if participants_inter6 == "Dominican Republic"
replace external_war = 0 if participants_inter7 == "Dominican Republic"
replace external_war = 0 if participants_inter8 == "Dominican Republic"
replace external_war = 0 if participants_inter9 == "Dominican Republic"
replace external_war = 0 if participants_inter10 == "Dominican Republic"
replace external_war = 0 if participants_inter11 == "Dominican Republic"
replace external_war = 0 if participants_inter12 =="Dominican Republic"
bysort year: egen tool = total(external_war) if Dominican_Republic_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Dominican Republic"
drop tool external_war participant* Dominican_Republic_neighbor
save "_Dominican_Republic_neighbors.dta", replace




use "war_default_dataset_participants.dta", clear
gen	Ecuador_neighbor  = 1 if country == "Colombia" | country == "Peru" 
replace external_war = 0 if participants_inter1 == "Ecuador"
replace external_war = 0 if participants_inter2 == "Ecuador"
replace external_war = 0 if participants_inter3 == "Ecuador"
replace external_war = 0 if participants_inter4 == "Ecuador"
replace external_war = 0 if participants_inter5 == "Ecuador"
replace external_war = 0 if participants_inter6 == "Ecuador"
replace external_war = 0 if participants_inter7 == "Ecuador"
replace external_war = 0 if participants_inter8 == "Ecuador"
replace external_war = 0 if participants_inter9 == "Ecuador"
replace external_war = 0 if participants_inter10 == "Ecuador"
replace external_war = 0 if participants_inter11 == "Ecuador"
replace external_war = 0 if participants_inter12 =="Ecuador"
bysort year: egen tool = total(external_war) if Ecuador_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Ecuador"
drop tool external_war participant* Ecuador_neighbor
save "_Ecuador_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Egypt_neighbor  = 1 if country == "Gaza Strip" | country == "Israel" | country == "Libya" | country == "Sudan" 
replace external_war = 0 if participants_inter1 == "Egypt"
replace external_war = 0 if participants_inter2 == "Egypt"
replace external_war = 0 if participants_inter3 == "Egypt"
replace external_war = 0 if participants_inter4 == "Egypt"
replace external_war = 0 if participants_inter5 == "Egypt"
replace external_war = 0 if participants_inter6 == "Egypt"
replace external_war = 0 if participants_inter7 == "Egypt"
replace external_war = 0 if participants_inter8 == "Egypt"
replace external_war = 0 if participants_inter9 == "Egypt"
replace external_war = 0 if participants_inter10 == "Egypt"
replace external_war = 0 if participants_inter11 == "Egypt"
replace external_war = 0 if participants_inter12 =="Egypt"
bysort year: egen tool = total(external_war) if Egypt_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Egypt"
drop tool external_war participant* Egypt_neighbor
save "_Egypt_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	El_Salvador_neighbor  = 1 if country == "Guatemala" | country == "Honduras" 
replace external_war = 0 if participants_inter1 == "El Salvador"
replace external_war = 0 if participants_inter2 == "El Salvador"
replace external_war = 0 if participants_inter3 == "El Salvador"
replace external_war = 0 if participants_inter4 == "El Salvador"
replace external_war = 0 if participants_inter5 == "El Salvador"
replace external_war = 0 if participants_inter6 == "El Salvador"
replace external_war = 0 if participants_inter7 == "El Salvador"
replace external_war = 0 if participants_inter8 == "El Salvador"
replace external_war = 0 if participants_inter9 == "El Salvador"
replace external_war = 0 if participants_inter10 == "El Salvador"
replace external_war = 0 if participants_inter11 == "El Salvador"
replace external_war = 0 if participants_inter12 =="El Salvador"
bysort year: egen tool = total(external_war) if El_Salvador_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "El Salvador"
drop tool external_war participant* El_Salvador_neighbor
save "_El_Salvador_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Estonia_neighbor  = 1 if country == "Latvia" | country == "Russia" 
replace external_war = 0 if participants_inter1 == "Estonia"
replace external_war = 0 if participants_inter2 == "Estonia"
replace external_war = 0 if participants_inter3 == "Estonia"
replace external_war = 0 if participants_inter4 == "Estonia"
replace external_war = 0 if participants_inter5 == "Estonia"
replace external_war = 0 if participants_inter6 == "Estonia"
replace external_war = 0 if participants_inter7 == "Estonia"
replace external_war = 0 if participants_inter8 == "Estonia"
replace external_war = 0 if participants_inter9 == "Estonia"
replace external_war = 0 if participants_inter10 == "Estonia"
replace external_war = 0 if participants_inter11 == "Estonia"
replace external_war = 0 if participants_inter12 =="Estonia"
bysort year: egen tool = total(external_war) if Estonia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Estonia"
drop tool external_war participant* Estonia_neighbor
save "_Estonia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Ethiopia_neighbor  = 1 if country == "Djibouti" | country == "Eritrea" | country == "Kenya" | country == "Somalia" | country == "South Sudan" | country == "Sudan" 
replace external_war = 0 if participants_inter1 == "Ethiopia"
replace external_war = 0 if participants_inter2 == "Ethiopia"
replace external_war = 0 if participants_inter3 == "Ethiopia"
replace external_war = 0 if participants_inter4 == "Ethiopia"
replace external_war = 0 if participants_inter5 == "Ethiopia"
replace external_war = 0 if participants_inter6 == "Ethiopia"
replace external_war = 0 if participants_inter7 == "Ethiopia"
replace external_war = 0 if participants_inter8 == "Ethiopia"
replace external_war = 0 if participants_inter9 == "Ethiopia"
replace external_war = 0 if participants_inter10 == "Ethiopia"
replace external_war = 0 if participants_inter11 == "Ethiopia"
replace external_war = 0 if participants_inter12 =="Ethiopia"
bysort year: egen tool = total(external_war) if Ethiopia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Ethiopia"
drop tool external_war participant* Ethiopia_neighbor
save "_Ethiopia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Finland_neighbor  = 1 if country == "Norway" | country == "Russia" | country == "Sweden" 
replace external_war = 0 if participants_inter1 == "Finland"
replace external_war = 0 if participants_inter2 == "Finland"
replace external_war = 0 if participants_inter3 == "Finland"
replace external_war = 0 if participants_inter4 == "Finland"
replace external_war = 0 if participants_inter5 == "Finland"
replace external_war = 0 if participants_inter6 == "Finland"
replace external_war = 0 if participants_inter7 == "Finland"
replace external_war = 0 if participants_inter8 == "Finland"
replace external_war = 0 if participants_inter9 == "Finland"
replace external_war = 0 if participants_inter10 == "Finland"
replace external_war = 0 if participants_inter11 == "Finland"
replace external_war = 0 if participants_inter12 =="Finland"
bysort year: egen tool = total(external_war) if Finland_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Finland"
drop tool external_war participant* Finland_neighbor
save "_Finland_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	France_neighbor  = 1 if country == "Andorra" | country == "Belgium" | country == "Germany" | country == "Italy" | country == "Luxembourg" | country == "Monaco" | country == "Spain" | country == "Switzerland" 
replace external_war = 0 if participants_inter1 == "France"
replace external_war = 0 if participants_inter2 == "France"
replace external_war = 0 if participants_inter3 == "France"
replace external_war = 0 if participants_inter4 == "France"
replace external_war = 0 if participants_inter5 == "France"
replace external_war = 0 if participants_inter6 == "France"
replace external_war = 0 if participants_inter7 == "France"
replace external_war = 0 if participants_inter8 == "France"
replace external_war = 0 if participants_inter9 == "France"
replace external_war = 0 if participants_inter10 == "France"
replace external_war = 0 if participants_inter11 == "France"
replace external_war = 0 if participants_inter12 =="France"
bysort year: egen tool = total(external_war) if France_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "France"
drop tool external_war participant* France_neighbor
save "_France_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Georgia_neighbor  = 1 if country == "Armenia" | country == "Azerbaijan" | country == "Russia" | country == "Turkey" 
replace external_war = 0 if participants_inter1 == "Georgia"
replace external_war = 0 if participants_inter2 == "Georgia"
replace external_war = 0 if participants_inter3 == "Georgia"
replace external_war = 0 if participants_inter4 == "Georgia"
replace external_war = 0 if participants_inter5 == "Georgia"
replace external_war = 0 if participants_inter6 == "Georgia"
replace external_war = 0 if participants_inter7 == "Georgia"
replace external_war = 0 if participants_inter8 == "Georgia"
replace external_war = 0 if participants_inter9 == "Georgia"
replace external_war = 0 if participants_inter10 == "Georgia"
replace external_war = 0 if participants_inter11 == "Georgia"
replace external_war = 0 if participants_inter12 =="Georgia"
bysort year: egen tool = total(external_war) if Georgia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Georgia"
drop tool external_war participant* Georgia_neighbor
save "_Georgia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Germany_neighbor  = 1 if country == "Austria" | country == "Belgium" | country == "Czech Republic" | country == "Denmark" | country == "France" | country == "Luxembourg" | country == "Netherlands" | country == "Poland" | country == "Switzerland" 
replace external_war = 0 if participants_inter1 == "Germany"
replace external_war = 0 if participants_inter2 == "Germany"
replace external_war = 0 if participants_inter3 == "Germany"
replace external_war = 0 if participants_inter4 == "Germany"
replace external_war = 0 if participants_inter5 == "Germany"
replace external_war = 0 if participants_inter6 == "Germany"
replace external_war = 0 if participants_inter7 == "Germany"
replace external_war = 0 if participants_inter8 == "Germany"
replace external_war = 0 if participants_inter9 == "Germany"
replace external_war = 0 if participants_inter10 == "Germany"
replace external_war = 0 if participants_inter11 == "Germany"
replace external_war = 0 if participants_inter12 =="Germany"
bysort year: egen tool = total(external_war) if Germany_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Germany"
drop tool external_war participant* Germany_neighbor
save "_Germany_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Greece_neighbor  = 1 if country == "Albania" | country == "Bulgaria" | country == "Macedonia" | country == "Turkey" 
replace external_war = 0 if participants_inter1 == "Greece"
replace external_war = 0 if participants_inter2 == "Greece"
replace external_war = 0 if participants_inter3 == "Greece"
replace external_war = 0 if participants_inter4 == "Greece"
replace external_war = 0 if participants_inter5 == "Greece"
replace external_war = 0 if participants_inter6 == "Greece"
replace external_war = 0 if participants_inter7 == "Greece"
replace external_war = 0 if participants_inter8 == "Greece"
replace external_war = 0 if participants_inter9 == "Greece"
replace external_war = 0 if participants_inter10 == "Greece"
replace external_war = 0 if participants_inter11 == "Greece"
replace external_war = 0 if participants_inter12 =="Greece"
bysort year: egen tool = total(external_war) if Greece_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Greece"
drop tool external_war participant* Greece_neighbor
save "_Greece_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Guatemala_neighbor  = 1 if country == "Belize" | country == "El Salvador" | country == "Honduras" | country == "Mexico" 
replace external_war = 0 if participants_inter1 == "Guatemala"
replace external_war = 0 if participants_inter2 == "Guatemala"
replace external_war = 0 if participants_inter3 == "Guatemala"
replace external_war = 0 if participants_inter4 == "Guatemala"
replace external_war = 0 if participants_inter5 == "Guatemala"
replace external_war = 0 if participants_inter6 == "Guatemala"
replace external_war = 0 if participants_inter7 == "Guatemala"
replace external_war = 0 if participants_inter8 == "Guatemala"
replace external_war = 0 if participants_inter9 == "Guatemala"
replace external_war = 0 if participants_inter10 == "Guatemala"
replace external_war = 0 if participants_inter11 == "Guatemala"
replace external_war = 0 if participants_inter12 =="Guatemala"
bysort year: egen tool = total(external_war) if Guatemala_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Guatemala"
drop tool external_war participant* Guatemala_neighbor
save "_Guatemala_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Guinea_neighbor  = 1 if country == "Guinea-Bissau" | country == "Ivory Coast" | country == "Liberia" | country == "Mali" | country == "Senegal" | country == "Sierra Leone" 
replace external_war = 0 if participants_inter1 == "Guinea"
replace external_war = 0 if participants_inter2 == "Guinea"
replace external_war = 0 if participants_inter3 == "Guinea"
replace external_war = 0 if participants_inter4 == "Guinea"
replace external_war = 0 if participants_inter5 == "Guinea"
replace external_war = 0 if participants_inter6 == "Guinea"
replace external_war = 0 if participants_inter7 == "Guinea"
replace external_war = 0 if participants_inter8 == "Guinea"
replace external_war = 0 if participants_inter9 == "Guinea"
replace external_war = 0 if participants_inter10 == "Guinea"
replace external_war = 0 if participants_inter11 == "Guinea"
replace external_war = 0 if participants_inter12 =="Guinea"
bysort year: egen tool = total(external_war) if Guinea_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Guinea"
drop tool external_war participant* Guinea_neighbor
save "_Guinea_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Honduras_neighbor  = 1 if country == "El Salvador" | country == "Guatemala" | country == "Nicaragua" 
replace external_war = 0 if participants_inter1 == "Honduras"
replace external_war = 0 if participants_inter2 == "Honduras"
replace external_war = 0 if participants_inter3 == "Honduras"
replace external_war = 0 if participants_inter4 == "Honduras"
replace external_war = 0 if participants_inter5 == "Honduras"
replace external_war = 0 if participants_inter6 == "Honduras"
replace external_war = 0 if participants_inter7 == "Honduras"
replace external_war = 0 if participants_inter8 == "Honduras"
replace external_war = 0 if participants_inter9 == "Honduras"
replace external_war = 0 if participants_inter10 == "Honduras"
replace external_war = 0 if participants_inter11 == "Honduras"
replace external_war = 0 if participants_inter12 =="Honduras"
bysort year: egen tool = total(external_war) if Honduras_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Honduras"
drop tool external_war participant* Honduras_neighbor
save "_Honduras_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Hungary_neighbor  = 1 if country == "Austria" | country == "Croatia" | country == "Romania" | country == "Serbia" | country == "Slovakia" | country == "Slovenia" | country == "Ukraine" 
replace external_war = 0 if participants_inter1 == "Hungary"
replace external_war = 0 if participants_inter2 == "Hungary"
replace external_war = 0 if participants_inter3 == "Hungary"
replace external_war = 0 if participants_inter4 == "Hungary"
replace external_war = 0 if participants_inter5 == "Hungary"
replace external_war = 0 if participants_inter6 == "Hungary"
replace external_war = 0 if participants_inter7 == "Hungary"
replace external_war = 0 if participants_inter8 == "Hungary"
replace external_war = 0 if participants_inter9 == "Hungary"
replace external_war = 0 if participants_inter10 == "Hungary"
replace external_war = 0 if participants_inter11 == "Hungary"
replace external_war = 0 if participants_inter12 =="Hungary"
bysort year: egen tool = total(external_war) if Hungary_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Hungary"
drop tool external_war participant* Hungary_neighbor
save "_Hungary_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	India_neighbor  = 1 if country == "Bangladesh" | country == "Bhutan" | country == "China" | country == "Myanmar" | country == "Nepal" | country == "Pakistan" 
replace external_war = 0 if participants_inter1 == "India"
replace external_war = 0 if participants_inter2 == "India"
replace external_war = 0 if participants_inter3 == "India"
replace external_war = 0 if participants_inter4 == "India"
replace external_war = 0 if participants_inter5 == "India"
replace external_war = 0 if participants_inter6 == "India"
replace external_war = 0 if participants_inter7 == "India"
replace external_war = 0 if participants_inter8 == "India"
replace external_war = 0 if participants_inter9 == "India"
replace external_war = 0 if participants_inter10 == "India"
replace external_war = 0 if participants_inter11 == "India"
replace external_war = 0 if participants_inter12 =="India"
bysort year: egen tool = total(external_war) if India_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "India"
drop tool external_war participant* India_neighbor
save "_India_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Indonesia_neighbor  = 1 if country == "East_Timor" | country == "Malaysia" | country == "Papua New Guinea" 
replace external_war = 0 if participants_inter1 == "Indonesia"
replace external_war = 0 if participants_inter2 == "Indonesia"
replace external_war = 0 if participants_inter3 == "Indonesia"
replace external_war = 0 if participants_inter4 == "Indonesia"
replace external_war = 0 if participants_inter5 == "Indonesia"
replace external_war = 0 if participants_inter6 == "Indonesia"
replace external_war = 0 if participants_inter7 == "Indonesia"
replace external_war = 0 if participants_inter8 == "Indonesia"
replace external_war = 0 if participants_inter9 == "Indonesia"
replace external_war = 0 if participants_inter10 == "Indonesia"
replace external_war = 0 if participants_inter11 == "Indonesia"
replace external_war = 0 if participants_inter12 =="Indonesia"
bysort year: egen tool = total(external_war) if Indonesia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Indonesia"
drop tool external_war participant* Indonesia_neighbor
save "_Indonesia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Iran_neighbor  = 1 if country == "Afghanistan" | country == "Armenia" | country == "Azerbaijan" | country == "Iraq" | country == "Pakistan" | country == "Turkey" | country == "Turkmenistan" 
replace external_war = 0 if participants_inter1 == "Iran"
replace external_war = 0 if participants_inter2 == "Iran"
replace external_war = 0 if participants_inter3 == "Iran"
replace external_war = 0 if participants_inter4 == "Iran"
replace external_war = 0 if participants_inter5 == "Iran"
replace external_war = 0 if participants_inter6 == "Iran"
replace external_war = 0 if participants_inter7 == "Iran"
replace external_war = 0 if participants_inter8 == "Iran"
replace external_war = 0 if participants_inter9 == "Iran"
replace external_war = 0 if participants_inter10 == "Iran"
replace external_war = 0 if participants_inter11 == "Iran"
replace external_war = 0 if participants_inter12 =="Iran"
bysort year: egen tool = total(external_war) if Iran_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Iran"
drop tool external_war participant* Iran_neighbor
save "_Iran_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Ireland_neighbor  = 1 if country == "United_Kingdom" 
replace external_war = 0 if participants_inter1 == "Ireland"
replace external_war = 0 if participants_inter2 == "Ireland"
replace external_war = 0 if participants_inter3 == "Ireland"
replace external_war = 0 if participants_inter4 == "Ireland"
replace external_war = 0 if participants_inter5 == "Ireland"
replace external_war = 0 if participants_inter6 == "Ireland"
replace external_war = 0 if participants_inter7 == "Ireland"
replace external_war = 0 if participants_inter8 == "Ireland"
replace external_war = 0 if participants_inter9 == "Ireland"
replace external_war = 0 if participants_inter10 == "Ireland"
replace external_war = 0 if participants_inter11 == "Ireland"
replace external_war = 0 if participants_inter12 =="Ireland"
bysort year: egen tool = total(external_war) if Ireland_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Ireland"
drop tool external_war participant* Ireland_neighbor
save "_Ireland_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Israel_neighbor  = 1 if country == "Egypt" | country == "Gaza Strip" | country == "Jordan" | country == "Lebanon" | country == "Syria" | country == "West Bank" 
replace external_war = 0 if participants_inter1 == "Israel"
replace external_war = 0 if participants_inter2 == "Israel"
replace external_war = 0 if participants_inter3 == "Israel"
replace external_war = 0 if participants_inter4 == "Israel"
replace external_war = 0 if participants_inter5 == "Israel"
replace external_war = 0 if participants_inter6 == "Israel"
replace external_war = 0 if participants_inter7 == "Israel"
replace external_war = 0 if participants_inter8 == "Israel"
replace external_war = 0 if participants_inter9 == "Israel"
replace external_war = 0 if participants_inter10 == "Israel"
replace external_war = 0 if participants_inter11 == "Israel"
replace external_war = 0 if participants_inter12 =="Israel"
bysort year: egen tool = total(external_war) if Israel_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Israel"
drop tool external_war participant* Israel_neighbor
save "_Israel_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Italy_neighbor  = 1 if country == "Austria" | country == "France" | country == "San Marino" | country == "Slovenia" | country == "Switzerland" | country == "Vatican City" 
replace external_war = 0 if participants_inter1 == "Italy"
replace external_war = 0 if participants_inter2 == "Italy"
replace external_war = 0 if participants_inter3 == "Italy"
replace external_war = 0 if participants_inter4 == "Italy"
replace external_war = 0 if participants_inter5 == "Italy"
replace external_war = 0 if participants_inter6 == "Italy"
replace external_war = 0 if participants_inter7 == "Italy"
replace external_war = 0 if participants_inter8 == "Italy"
replace external_war = 0 if participants_inter9 == "Italy"
replace external_war = 0 if participants_inter10 == "Italy"
replace external_war = 0 if participants_inter11 == "Italy"
replace external_war = 0 if participants_inter12 =="Italy"
bysort year: egen tool = total(external_war) if Italy_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Italy"
drop tool external_war participant* Italy_neighbor
save "_Italy_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Ivory_Coast_neighbor  = 1 if country == "Burkina Faso" | country == "Ghana" | country == "Guinea" | country == "Liberia" | country == "Mali" 
replace external_war = 0 if participants_inter1 == "Ivory Coast"
replace external_war = 0 if participants_inter2 == "Ivory Coast"
replace external_war = 0 if participants_inter3 == "Ivory Coast"
replace external_war = 0 if participants_inter4 == "Ivory Coast"
replace external_war = 0 if participants_inter5 == "Ivory Coast"
replace external_war = 0 if participants_inter6 == "Ivory Coast"
replace external_war = 0 if participants_inter7 == "Ivory Coast"
replace external_war = 0 if participants_inter8 == "Ivory Coast"
replace external_war = 0 if participants_inter9 == "Ivory Coast"
replace external_war = 0 if participants_inter10 == "Ivory Coast"
replace external_war = 0 if participants_inter11 == "Ivory Coast"
replace external_war = 0 if participants_inter12 =="Ivory Coast"
bysort year: egen tool = total(external_war) if Ivory_Coast_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Ivory Coast"
drop tool external_war participant* Ivory_Coast_neighbor
save "_Ivory_Coast_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Kazakhstan_neighbor  = 1 if country == "China" | country == "Kyrgyzstan" | country == "Russia" | country == "Turkmenistan" | country == "Uzbekistan" 
replace external_war = 0 if participants_inter1 == "Kazakhstan"
replace external_war = 0 if participants_inter2 == "Kazakhstan"
replace external_war = 0 if participants_inter3 == "Kazakhstan"
replace external_war = 0 if participants_inter4 == "Kazakhstan"
replace external_war = 0 if participants_inter5 == "Kazakhstan"
replace external_war = 0 if participants_inter6 == "Kazakhstan"
replace external_war = 0 if participants_inter7 == "Kazakhstan"
replace external_war = 0 if participants_inter8 == "Kazakhstan"
replace external_war = 0 if participants_inter9 == "Kazakhstan"
replace external_war = 0 if participants_inter10 == "Kazakhstan"
replace external_war = 0 if participants_inter11 == "Kazakhstan"
replace external_war = 0 if participants_inter12 =="Kazakhstan"
bysort year: egen tool = total(external_war) if Kazakhstan_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Kazakhstan"
drop tool external_war participant* Kazakhstan_neighbor
save "_Kazakhstan_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Kenya_neighbor  = 1 if country == "Ethiopia" | country == "Somalia" | country == "South Sudan" | country == "Tanzania" | country == "Uganda" 
replace external_war = 0 if participants_inter1 == "Kenya"
replace external_war = 0 if participants_inter2 == "Kenya"
replace external_war = 0 if participants_inter3 == "Kenya"
replace external_war = 0 if participants_inter4 == "Kenya"
replace external_war = 0 if participants_inter5 == "Kenya"
replace external_war = 0 if participants_inter6 == "Kenya"
replace external_war = 0 if participants_inter7 == "Kenya"
replace external_war = 0 if participants_inter8 == "Kenya"
replace external_war = 0 if participants_inter9 == "Kenya"
replace external_war = 0 if participants_inter10 == "Kenya"
replace external_war = 0 if participants_inter11 == "Kenya"
replace external_war = 0 if participants_inter12 =="Kenya"
bysort year: egen tool = total(external_war) if Kenya_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Kenya"
drop tool external_war participant* Kenya_neighbor
save "_Kenya_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Latvia_neighbor  = 1 if country == "Belarus" | country == "Estonia" | country == "Lithuania" | country == "Russia" 
replace external_war = 0 if participants_inter1 == "Latvia"
replace external_war = 0 if participants_inter2 == "Latvia"
replace external_war = 0 if participants_inter3 == "Latvia"
replace external_war = 0 if participants_inter4 == "Latvia"
replace external_war = 0 if participants_inter5 == "Latvia"
replace external_war = 0 if participants_inter6 == "Latvia"
replace external_war = 0 if participants_inter7 == "Latvia"
replace external_war = 0 if participants_inter8 == "Latvia"
replace external_war = 0 if participants_inter9 == "Latvia"
replace external_war = 0 if participants_inter10 == "Latvia"
replace external_war = 0 if participants_inter11 == "Latvia"
replace external_war = 0 if participants_inter12 =="Latvia"
bysort year: egen tool = total(external_war) if Latvia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Latvia"
drop tool external_war participant* Latvia_neighbor
save "_Latvia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Lebanon_neighbor  = 1 if country == "Israel" | country == "Syria" 
replace external_war = 0 if participants_inter1 == "Lebanon"
replace external_war = 0 if participants_inter2 == "Lebanon"
replace external_war = 0 if participants_inter3 == "Lebanon"
replace external_war = 0 if participants_inter4 == "Lebanon"
replace external_war = 0 if participants_inter5 == "Lebanon"
replace external_war = 0 if participants_inter6 == "Lebanon"
replace external_war = 0 if participants_inter7 == "Lebanon"
replace external_war = 0 if participants_inter8 == "Lebanon"
replace external_war = 0 if participants_inter9 == "Lebanon"
replace external_war = 0 if participants_inter10 == "Lebanon"
replace external_war = 0 if participants_inter11 == "Lebanon"
replace external_war = 0 if participants_inter12 =="Lebanon"
bysort year: egen tool = total(external_war) if Lebanon_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Lebanon"
drop tool external_war participant* Lebanon_neighbor
save "_Lebanon_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Lesotho_neighbor  = 1 if country == "South Africa" 
replace external_war = 0 if participants_inter1 == "Lesotho"
replace external_war = 0 if participants_inter2 == "Lesotho"
replace external_war = 0 if participants_inter3 == "Lesotho"
replace external_war = 0 if participants_inter4 == "Lesotho"
replace external_war = 0 if participants_inter5 == "Lesotho"
replace external_war = 0 if participants_inter6 == "Lesotho"
replace external_war = 0 if participants_inter7 == "Lesotho"
replace external_war = 0 if participants_inter8 == "Lesotho"
replace external_war = 0 if participants_inter9 == "Lesotho"
replace external_war = 0 if participants_inter10 == "Lesotho"
replace external_war = 0 if participants_inter11 == "Lesotho"
replace external_war = 0 if participants_inter12 =="Lesotho"
bysort year: egen tool = total(external_war) if Lesotho_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Lesotho"
drop tool external_war participant* Lesotho_neighbor
save "_Lesotho_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Lithuania_neighbor  = 1 if country == "Belarus" | country == "Latvia" | country == "Poland" | country == "Russia" 
replace external_war = 0 if participants_inter1 == "Lithuania"
replace external_war = 0 if participants_inter2 == "Lithuania"
replace external_war = 0 if participants_inter3 == "Lithuania"
replace external_war = 0 if participants_inter4 == "Lithuania"
replace external_war = 0 if participants_inter5 == "Lithuania"
replace external_war = 0 if participants_inter6 == "Lithuania"
replace external_war = 0 if participants_inter7 == "Lithuania"
replace external_war = 0 if participants_inter8 == "Lithuania"
replace external_war = 0 if participants_inter9 == "Lithuania"
replace external_war = 0 if participants_inter10 == "Lithuania"
replace external_war = 0 if participants_inter11 == "Lithuania"
replace external_war = 0 if participants_inter12 =="Lithuania"
bysort year: egen tool = total(external_war) if Lithuania_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Lithuania"
drop tool external_war participant* Lithuania_neighbor
save "_Lithuania_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Macedonia_neighbor  = 1 if country == "Albania" | country == "Bulgaria" | country == "Greece" | country == "Kosovo" | country == "Serbia" 
replace external_war = 0 if participants_inter1 == "Macedonia"
replace external_war = 0 if participants_inter2 == "Macedonia"
replace external_war = 0 if participants_inter3 == "Macedonia"
replace external_war = 0 if participants_inter4 == "Macedonia"
replace external_war = 0 if participants_inter5 == "Macedonia"
replace external_war = 0 if participants_inter6 == "Macedonia"
replace external_war = 0 if participants_inter7 == "Macedonia"
replace external_war = 0 if participants_inter8 == "Macedonia"
replace external_war = 0 if participants_inter9 == "Macedonia"
replace external_war = 0 if participants_inter10 == "Macedonia"
replace external_war = 0 if participants_inter11 == "Macedonia"
replace external_war = 0 if participants_inter12 =="Macedonia"
bysort year: egen tool = total(external_war) if Macedonia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Macedonia"
drop tool external_war participant* Macedonia_neighbor
save "_Macedonia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Malaysia_neighbor  = 1 if country == "Brunei" | country == "Indonesia" | country == "Thailand" 
replace external_war = 0 if participants_inter1 == "Malaysia"
replace external_war = 0 if participants_inter2 == "Malaysia"
replace external_war = 0 if participants_inter3 == "Malaysia"
replace external_war = 0 if participants_inter4 == "Malaysia"
replace external_war = 0 if participants_inter5 == "Malaysia"
replace external_war = 0 if participants_inter6 == "Malaysia"
replace external_war = 0 if participants_inter7 == "Malaysia"
replace external_war = 0 if participants_inter8 == "Malaysia"
replace external_war = 0 if participants_inter9 == "Malaysia"
replace external_war = 0 if participants_inter10 == "Malaysia"
replace external_war = 0 if participants_inter11 == "Malaysia"
replace external_war = 0 if participants_inter12 =="Malaysia"
bysort year: egen tool = total(external_war) if Malaysia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Malaysia"
drop tool external_war participant* Malaysia_neighbor
save "_Malaysia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Mali_neighbor  = 1 if country == "Mali" | country == "Burkina Faso" | country == "Guinea" | country == "Ivory Coast" | country == "Mauritania" | country == "Niger" | country == "Senegal" 
replace external_war = 0 if participants_inter1 == "Argentina"
replace external_war = 0 if participants_inter2 == "Mali"
replace external_war = 0 if participants_inter3 == "Mali"
replace external_war = 0 if participants_inter4 == "Mali"
replace external_war = 0 if participants_inter5 == "Mali"
replace external_war = 0 if participants_inter6 == "Mali"
replace external_war = 0 if participants_inter7 == "Mali"
replace external_war = 0 if participants_inter8 == "Mali"
replace external_war = 0 if participants_inter9 == "Mali"
replace external_war = 0 if participants_inter10 == "Mali"
replace external_war = 0 if participants_inter11 == "Mali"
replace external_war = 0 if participants_inter12 =="Mali"
bysort year: egen tool = total(external_war) if Mali_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Mali"
drop tool external_war participant* Mali_neighbor
save "_Mali_neighbors.dta", replace

use "war_default_dataset_participants.dta", clear
gen	Mexico_neighbor  = 1 if country == "Belize" | country == "Guatemala" | country == "United States of America" 
replace external_war = 0 if participants_inter1 == "Mexico"
replace external_war = 0 if participants_inter2 == "Mexico"
replace external_war = 0 if participants_inter3 == "Mexico"
replace external_war = 0 if participants_inter4 == "Mexico"
replace external_war = 0 if participants_inter5 == "Mexico"
replace external_war = 0 if participants_inter6 == "Mexico"
replace external_war = 0 if participants_inter7 == "Mexico"
replace external_war = 0 if participants_inter8 == "Mexico"
replace external_war = 0 if participants_inter9 == "Mexico"
replace external_war = 0 if participants_inter10 == "Mexico"
replace external_war = 0 if participants_inter11 == "Mexico"
replace external_war = 0 if participants_inter12 =="Mexico"
bysort year: egen tool = total(external_war) if Mexico_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Mexico"
drop tool external_war participant* Mexico_neighbor
save "_Mexico_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Moldova_neighbor  = 1 if country == "Romania" | country == "Ukraine" 
replace external_war = 0 if participants_inter1 == "Moldova"
replace external_war = 0 if participants_inter2 == "Moldova"
replace external_war = 0 if participants_inter3 == "Moldova"
replace external_war = 0 if participants_inter4 == "Moldova"
replace external_war = 0 if participants_inter5 == "Moldova"
replace external_war = 0 if participants_inter6 == "Moldova"
replace external_war = 0 if participants_inter7 == "Moldova"
replace external_war = 0 if participants_inter8 == "Moldova"
replace external_war = 0 if participants_inter9 == "Moldova"
replace external_war = 0 if participants_inter10 == "Moldova"
replace external_war = 0 if participants_inter11 == "Moldova"
replace external_war = 0 if participants_inter12 =="Moldova"
bysort year: egen tool = total(external_war) if Moldova_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Moldova"
drop tool external_war participant* Moldova_neighbor
save "_Moldova_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Mongolia_neighbor  = 1 if country == "China" | country == "Russia" 
replace external_war = 0 if participants_inter1 == "Mongolia"
replace external_war = 0 if participants_inter2 == "Mongolia"
replace external_war = 0 if participants_inter3 == "Mongolia"
replace external_war = 0 if participants_inter4 == "Mongolia"
replace external_war = 0 if participants_inter5 == "Mongolia"
replace external_war = 0 if participants_inter6 == "Mongolia"
replace external_war = 0 if participants_inter7 == "Mongolia"
replace external_war = 0 if participants_inter8 == "Mongolia"
replace external_war = 0 if participants_inter9 == "Mongolia"
replace external_war = 0 if participants_inter10 == "Mongolia"
replace external_war = 0 if participants_inter11 == "Mongolia"
replace external_war = 0 if participants_inter12 =="Mongolia"
bysort year: egen tool = total(external_war) if Mongolia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Mongolia"
drop tool external_war participant* Mongolia_neighbor
save "_Mongolia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Morocco_neighbor  = 1 if country == "Morocco" | country == "Spain" | country == "Western Sahara" 
replace external_war = 0 if participants_inter1 == "Morocco"
replace external_war = 0 if participants_inter2 == "Morocco"
replace external_war = 0 if participants_inter3 == "Morocco"
replace external_war = 0 if participants_inter4 == "Morocco"
replace external_war = 0 if participants_inter5 == "Morocco"
replace external_war = 0 if participants_inter6 == "Morocco"
replace external_war = 0 if participants_inter7 == "Morocco"
replace external_war = 0 if participants_inter8 == "Morocco"
replace external_war = 0 if participants_inter9 == "Morocco"
replace external_war = 0 if participants_inter10 == "Morocco"
replace external_war = 0 if participants_inter11 == "Morocco"
replace external_war = 0 if participants_inter12 =="Morocco"
bysort year: egen tool = total(external_war) if Morocco_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Morocco"
drop tool external_war participant* Morocco_neighbor
save "_Morocco_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Myanmar_neighbor  = 1 if country == "Bangladesh" | country == "China" | country == "India" | country == "Laos" | country == "Thailand" 
replace external_war = 0 if participants_inter1 == "Myanmar"
replace external_war = 0 if participants_inter2 == "Myanmar"
replace external_war = 0 if participants_inter3 == "Myanmar"
replace external_war = 0 if participants_inter4 == "Myanmar"
replace external_war = 0 if participants_inter5 == "Myanmar"
replace external_war = 0 if participants_inter6 == "Myanmar"
replace external_war = 0 if participants_inter7 == "Myanmar"
replace external_war = 0 if participants_inter8 == "Myanmar"
replace external_war = 0 if participants_inter9 == "Myanmar"
replace external_war = 0 if participants_inter10 == "Myanmar"
replace external_war = 0 if participants_inter11 == "Myanmar"
replace external_war = 0 if participants_inter12 =="Myanmar"
bysort year: egen tool = total(external_war) if Myanmar_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Myanmar"
drop tool external_war participant* Myanmar_neighbor
save "_Myanmar_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Namibia_neighbor  = 1 if country == "Angola" | country == "Botswana" | country == "South Africa" | country == "Zambia" 
replace external_war = 0 if participants_inter1 == "Namibia"
replace external_war = 0 if participants_inter2 == "Namibia"
replace external_war = 0 if participants_inter3 == "Namibia"
replace external_war = 0 if participants_inter4 == "Namibia"
replace external_war = 0 if participants_inter5 == "Namibia"
replace external_war = 0 if participants_inter6 == "Namibia"
replace external_war = 0 if participants_inter7 == "Namibia"
replace external_war = 0 if participants_inter8 == "Namibia"
replace external_war = 0 if participants_inter9 == "Namibia"
replace external_war = 0 if participants_inter10 == "Namibia"
replace external_war = 0 if participants_inter11 == "Namibia"
replace external_war = 0 if participants_inter12 =="Namibia"
bysort year: egen tool = total(external_war) if Namibia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Namibia"
drop tool external_war participant* Namibia_neighbor
save "_Namibia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Nepal_neighbor  = 1 if country == "China" | country == "India" 
replace external_war = 0 if participants_inter1 == "Nepal"
replace external_war = 0 if participants_inter2 == "Nepal"
replace external_war = 0 if participants_inter3 == "Nepal"
replace external_war = 0 if participants_inter4 == "Nepal"
replace external_war = 0 if participants_inter5 == "Nepal"
replace external_war = 0 if participants_inter6 == "Nepal"
replace external_war = 0 if participants_inter7 == "Nepal"
replace external_war = 0 if participants_inter8 == "Nepal"
replace external_war = 0 if participants_inter9 == "Nepal"
replace external_war = 0 if participants_inter10 == "Nepal"
replace external_war = 0 if participants_inter11 == "Nepal"
replace external_war = 0 if participants_inter12 =="Nepal"
bysort year: egen tool = total(external_war) if Nepal_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Nepal"
drop tool external_war participant* Nepal_neighbor
save "_Nepal_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Netherlands_neighbor  = 1 if country == "Belgium" | country == "Germany" 
replace external_war = 0 if participants_inter1 == "Netherlands"
replace external_war = 0 if participants_inter2 == "Netherlands"
replace external_war = 0 if participants_inter3 == "Netherlands"
replace external_war = 0 if participants_inter4 == "Netherlands"
replace external_war = 0 if participants_inter5 == "Netherlands"
replace external_war = 0 if participants_inter6 == "Netherlands"
replace external_war = 0 if participants_inter7 == "Netherlands"
replace external_war = 0 if participants_inter8 == "Netherlands"
replace external_war = 0 if participants_inter9 == "Netherlands"
replace external_war = 0 if participants_inter10 == "Netherlands"
replace external_war = 0 if participants_inter11 == "Netherlands"
replace external_war = 0 if participants_inter12 =="Netherlands"
bysort year: egen tool = total(external_war) if Netherlands_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Netherlands"
drop tool external_war participant* Netherlands_neighbor
save "_Netherlands_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Nicaragua_neighbor  = 1 if country == "Costa Rica" | country == "Honduras" 
replace external_war = 0 if participants_inter1 == "Nicaragua"
replace external_war = 0 if participants_inter2 == "Nicaragua"
replace external_war = 0 if participants_inter3 == "Nicaragua"
replace external_war = 0 if participants_inter4 == "Nicaragua"
replace external_war = 0 if participants_inter5 == "Nicaragua"
replace external_war = 0 if participants_inter6 == "Nicaragua"
replace external_war = 0 if participants_inter7 == "Nicaragua"
replace external_war = 0 if participants_inter8 == "Nicaragua"
replace external_war = 0 if participants_inter9 == "Nicaragua"
replace external_war = 0 if participants_inter10 == "Nicaragua"
replace external_war = 0 if participants_inter11 == "Nicaragua"
replace external_war = 0 if participants_inter12 =="Nicaragua"
bysort year: egen tool = total(external_war) if Nicaragua_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Nicaragua"
drop tool external_war participant* Nicaragua_neighbor
save "_Nicaragua_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Nigeria_neighbor  = 1 if country == "Benin" | country == "Cameroon" | country == "Chad" | country == "Niger" 
replace external_war = 0 if participants_inter1 == "Nigeria"
replace external_war = 0 if participants_inter2 == "Nigeria"
replace external_war = 0 if participants_inter3 == "Nigeria"
replace external_war = 0 if participants_inter4 == "Nigeria"
replace external_war = 0 if participants_inter5 == "Nigeria"
replace external_war = 0 if participants_inter6 == "Nigeria"
replace external_war = 0 if participants_inter7 == "Nigeria"
replace external_war = 0 if participants_inter8 == "Nigeria"
replace external_war = 0 if participants_inter9 == "Nigeria"
replace external_war = 0 if participants_inter10 == "Nigeria"
replace external_war = 0 if participants_inter11 == "Nigeria"
replace external_war = 0 if participants_inter12 =="Nigeria"
bysort year: egen tool = total(external_war) if Nigeria_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Nigeria"
drop tool external_war participant* Nigeria_neighbor
save "_Nigeria_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Norway_neighbor  = 1 if country == "Finland" | country == "Russia" | country == "Sweden" 
replace external_war = 0 if participants_inter1 == "Norway"
replace external_war = 0 if participants_inter2 == "Norway"
replace external_war = 0 if participants_inter3 == "Norway"
replace external_war = 0 if participants_inter4 == "Norway"
replace external_war = 0 if participants_inter5 == "Norway"
replace external_war = 0 if participants_inter6 == "Norway"
replace external_war = 0 if participants_inter7 == "Norway"
replace external_war = 0 if participants_inter8 == "Norway"
replace external_war = 0 if participants_inter9 == "Norway"
replace external_war = 0 if participants_inter10 == "Norway"
replace external_war = 0 if participants_inter11 == "Norway"
replace external_war = 0 if participants_inter12 =="Norway"
bysort year: egen tool = total(external_war) if Norway_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Norway"
drop tool external_war participant* Norway_neighbor
save "_Norway_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Pakistan_neighbor  = 1 if country == "Afghanistan" | country == "China" | country == "India" | country == "Iran" 
replace external_war = 0 if participants_inter1 == "Pakistan"
replace external_war = 0 if participants_inter2 == "Pakistan"
replace external_war = 0 if participants_inter3 == "Pakistan"
replace external_war = 0 if participants_inter4 == "Pakistan"
replace external_war = 0 if participants_inter5 == "Pakistan"
replace external_war = 0 if participants_inter6 == "Pakistan"
replace external_war = 0 if participants_inter7 == "Pakistan"
replace external_war = 0 if participants_inter8 == "Pakistan"
replace external_war = 0 if participants_inter9 == "Pakistan"
replace external_war = 0 if participants_inter10 == "Pakistan"
replace external_war = 0 if participants_inter11 == "Pakistan"
replace external_war = 0 if participants_inter12 =="Pakistan"
bysort year: egen tool = total(external_war) if Pakistan_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Pakistan"
drop tool external_war participant* Pakistan_neighbor
save "_Pakistan_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Panama_neighbor  = 1 if country == "Colombia" | country == "Costa Rica" 
replace external_war = 0 if participants_inter1 == "Panama"
replace external_war = 0 if participants_inter2 == "Panama"
replace external_war = 0 if participants_inter3 == "Panama"
replace external_war = 0 if participants_inter4 == "Panama"
replace external_war = 0 if participants_inter5 == "Panama"
replace external_war = 0 if participants_inter6 == "Panama"
replace external_war = 0 if participants_inter7 == "Panama"
replace external_war = 0 if participants_inter8 == "Panama"
replace external_war = 0 if participants_inter9 == "Panama"
replace external_war = 0 if participants_inter10 == "Panama"
replace external_war = 0 if participants_inter11 == "Panama"
replace external_war = 0 if participants_inter12 =="Panama"
bysort year: egen tool = total(external_war) if Panama_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Panama"
drop tool external_war participant* Panama_neighbor
save "_Panama_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Paraguay_neighbor  = 1 if country == "Argentina" | country == "Bolivia" | country == "Brazil" 
replace external_war = 0 if participants_inter1 == "Paraguay"
replace external_war = 0 if participants_inter2 == "Paraguay"
replace external_war = 0 if participants_inter3 == "Paraguay"
replace external_war = 0 if participants_inter4 == "Paraguay"
replace external_war = 0 if participants_inter5 == "Paraguay"
replace external_war = 0 if participants_inter6 == "Paraguay"
replace external_war = 0 if participants_inter7 == "Paraguay"
replace external_war = 0 if participants_inter8 == "Paraguay"
replace external_war = 0 if participants_inter9 == "Paraguay"
replace external_war = 0 if participants_inter10 == "Paraguay"
replace external_war = 0 if participants_inter11 == "Paraguay"
replace external_war = 0 if participants_inter12 =="Paraguay"
bysort year: egen tool = total(external_war) if Paraguay_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Paraguay"
drop tool external_war participant* Paraguay_neighbor
save "_Paraguay_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Peru_neighbor  = 1 if country == "Bolivia" | country == "Brazil" | country == "Chile" | country == "Colombia" | country == "Ecuador" 
replace external_war = 0 if participants_inter1 == "Peru"
replace external_war = 0 if participants_inter2 == "Peru"
replace external_war = 0 if participants_inter3 == "Peru"
replace external_war = 0 if participants_inter4 == "Peru"
replace external_war = 0 if participants_inter5 == "Peru"
replace external_war = 0 if participants_inter6 == "Peru"
replace external_war = 0 if participants_inter7 == "Peru"
replace external_war = 0 if participants_inter8 == "Peru"
replace external_war = 0 if participants_inter9 == "Peru"
replace external_war = 0 if participants_inter10 == "Peru"
replace external_war = 0 if participants_inter11 == "Peru"
replace external_war = 0 if participants_inter12 =="Peru"
bysort year: egen tool = total(external_war) if Peru_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Peru"
drop tool external_war participant* Peru_neighbor
save "_Peru_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Poland_neighbor  = 1 if country == "Belarus" | country == "Czech Republic" | country == "Germany" | country == "Lithuania" | country == "Russia" | country == "Slovakia" | country == "Ukraine" 
replace external_war = 0 if participants_inter1 == "Poland"
replace external_war = 0 if participants_inter2 == "Poland"
replace external_war = 0 if participants_inter3 == "Poland"
replace external_war = 0 if participants_inter4 == "Poland"
replace external_war = 0 if participants_inter5 == "Poland"
replace external_war = 0 if participants_inter6 == "Poland"
replace external_war = 0 if participants_inter7 == "Poland"
replace external_war = 0 if participants_inter8 == "Poland"
replace external_war = 0 if participants_inter9 == "Poland"
replace external_war = 0 if participants_inter10 == "Poland"
replace external_war = 0 if participants_inter11 == "Poland"
replace external_war = 0 if participants_inter12 =="Poland"
bysort year: egen tool = total(external_war) if Poland_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Poland"
drop tool external_war participant* Poland_neighbor
save "_Poland_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Portugal_neighbor  = 1 if country == "Spain" 
replace external_war = 0 if participants_inter1 == "Portugal"
replace external_war = 0 if participants_inter2 == "Portugal"
replace external_war = 0 if participants_inter3 == "Portugal"
replace external_war = 0 if participants_inter4 == "Portugal"
replace external_war = 0 if participants_inter5 == "Portugal"
replace external_war = 0 if participants_inter6 == "Portugal"
replace external_war = 0 if participants_inter7 == "Portugal"
replace external_war = 0 if participants_inter8 == "Portugal"
replace external_war = 0 if participants_inter9 == "Portugal"
replace external_war = 0 if participants_inter10 == "Portugal"
replace external_war = 0 if participants_inter11 == "Portugal"
replace external_war = 0 if participants_inter12 =="Portugal"
bysort year: egen tool = total(external_war) if Portugal_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Portugal"
drop tool external_war participant* Portugal_neighbor
save "_Portugal_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Romania_neighbor  = 1 if country == "Bulgaria" | country == "Hungary" | country == "Moldova" | country == "Serbia" | country == "Ukraine" 
replace external_war = 0 if participants_inter1 == "Romania"
replace external_war = 0 if participants_inter2 == "Romania"
replace external_war = 0 if participants_inter3 == "Romania"
replace external_war = 0 if participants_inter4 == "Romania"
replace external_war = 0 if participants_inter5 == "Romania"
replace external_war = 0 if participants_inter6 == "Romania"
replace external_war = 0 if participants_inter7 == "Romania"
replace external_war = 0 if participants_inter8 == "Romania"
replace external_war = 0 if participants_inter9 == "Romania"
replace external_war = 0 if participants_inter10 == "Romania"
replace external_war = 0 if participants_inter11 == "Romania"
replace external_war = 0 if participants_inter12 =="Romania"
bysort year: egen tool = total(external_war) if Romania_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Romania"
drop tool external_war participant* Romania_neighbor
save "_Romania_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Russia_neighbor  = 1 if country == "Azerbaijan" | country == "Belarus" | country == "China" | country == "Estonia" | country == "Finland" | country == "Georgia" | country == "Kazakhstan" | country == "Latvia" | country == "Lithuania" | country == "Mongolia" | country == "North Korea" 	| country == "Norway"  	| country == "Poland"	| country == "Ukraine" 		
replace external_war = 0 if participants_inter1 == "Russia"
replace external_war = 0 if participants_inter2 == "Russia"
replace external_war = 0 if participants_inter3 == "Russia"
replace external_war = 0 if participants_inter4 == "Russia"
replace external_war = 0 if participants_inter5 == "Russia"
replace external_war = 0 if participants_inter6 == "Russia"
replace external_war = 0 if participants_inter7 == "Russia"
replace external_war = 0 if participants_inter8 == "Russia"
replace external_war = 0 if participants_inter9 == "Russia"
replace external_war = 0 if participants_inter10 == "Russia"
replace external_war = 0 if participants_inter11 == "Russia"
replace external_war = 0 if participants_inter12 =="Russia"
bysort year: egen tool = total(external_war) if Russia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Russia"
drop tool external_war participant* Russia_neighbor
save "_Russia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Rwanda_neighbor  = 1 if country == "Burundi" | country == "Democratic Republic of the Congo" | country == "Tanzania" | country == "Uganda" 
replace external_war = 0 if participants_inter1 == "Rwanda"
replace external_war = 0 if participants_inter2 == "Rwanda"
replace external_war = 0 if participants_inter3 == "Rwanda"
replace external_war = 0 if participants_inter4 == "Rwanda"
replace external_war = 0 if participants_inter5 == "Rwanda"
replace external_war = 0 if participants_inter6 == "Rwanda"
replace external_war = 0 if participants_inter7 == "Rwanda"
replace external_war = 0 if participants_inter8 == "Rwanda"
replace external_war = 0 if participants_inter9 == "Rwanda"
replace external_war = 0 if participants_inter10 == "Rwanda"
replace external_war = 0 if participants_inter11 == "Rwanda"
replace external_war = 0 if participants_inter12 =="Rwanda"
bysort year: egen tool = total(external_war) if Rwanda_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Rwanda"
drop tool external_war participant* Rwanda_neighbor
save "_Rwanda_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Senegal_neighbor  = 1 if country == "Gambia" | country == "Guinea" | country == "Guinea-Bissau" | country == "Mali" | country == "Mauritania" 
replace external_war = 0 if participants_inter1 == "Senegal"
replace external_war = 0 if participants_inter2 == "Senegal"
replace external_war = 0 if participants_inter3 == "Senegal"
replace external_war = 0 if participants_inter4 == "Senegal"
replace external_war = 0 if participants_inter5 == "Senegal"
replace external_war = 0 if participants_inter6 == "Senegal"
replace external_war = 0 if participants_inter7 == "Senegal"
replace external_war = 0 if participants_inter8 == "Senegal"
replace external_war = 0 if participants_inter9 == "Senegal"
replace external_war = 0 if participants_inter10 == "Senegal"
replace external_war = 0 if participants_inter11 == "Senegal"
replace external_war = 0 if participants_inter12 =="Senegal"
bysort year: egen tool = total(external_war) if Senegal_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Senegal"
drop tool external_war participant* Senegal_neighbor
save "_Senegal_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Slovakia_neighbor  = 1 if country == "Austria" | country == "Czech Republic" | country == "Hungary" | country == "Poland" | country == "Ukraine" 
replace external_war = 0 if participants_inter1 == "Slovakia"
replace external_war = 0 if participants_inter2 == "Slovakia"
replace external_war = 0 if participants_inter3 == "Slovakia"
replace external_war = 0 if participants_inter4 == "Slovakia"
replace external_war = 0 if participants_inter5 == "Slovakia"
replace external_war = 0 if participants_inter6 == "Slovakia"
replace external_war = 0 if participants_inter7 == "Slovakia"
replace external_war = 0 if participants_inter8 == "Slovakia"
replace external_war = 0 if participants_inter9 == "Slovakia"
replace external_war = 0 if participants_inter10 == "Slovakia"
replace external_war = 0 if participants_inter11 == "Slovakia"
replace external_war = 0 if participants_inter12 =="Slovakia"
bysort year: egen tool = total(external_war) if Slovakia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Slovakia"
drop tool external_war participant* Slovakia_neighbor
save "_Slovakia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Slovenia_neighbor  = 1 if country == "Austria" | country == "Croatia" | country == "Hungary" | country == "Italy" 
replace external_war = 0 if participants_inter1 == "Slovenia"
replace external_war = 0 if participants_inter2 == "Slovenia"
replace external_war = 0 if participants_inter3 == "Slovenia"
replace external_war = 0 if participants_inter4 == "Slovenia"
replace external_war = 0 if participants_inter5 == "Slovenia"
replace external_war = 0 if participants_inter6 == "Slovenia"
replace external_war = 0 if participants_inter7 == "Slovenia"
replace external_war = 0 if participants_inter8 == "Slovenia"
replace external_war = 0 if participants_inter9 == "Slovenia"
replace external_war = 0 if participants_inter10 == "Slovenia"
replace external_war = 0 if participants_inter11 == "Slovenia"
replace external_war = 0 if participants_inter12 =="Slovenia"
bysort year: egen tool = total(external_war) if Slovenia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Slovenia"
drop tool external_war participant* Slovenia_neighbor
save "_Slovenia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	South_Africa_neighbor  = 1 if country == "Botswana" | country == "Lesotho" | country == "Mozambique" | country == "Namibia" | country == "Swaziland" | country == "Zimbabwe" 
replace external_war = 0 if participants_inter1 == "South Africa"
replace external_war = 0 if participants_inter2 == "South Africa"
replace external_war = 0 if participants_inter3 == "South Africa"
replace external_war = 0 if participants_inter4 == "South Africa"
replace external_war = 0 if participants_inter5 == "South Africa"
replace external_war = 0 if participants_inter6 == "South Africa"
replace external_war = 0 if participants_inter7 == "South Africa"
replace external_war = 0 if participants_inter8 == "South Africa"
replace external_war = 0 if participants_inter9 == "South Africa"
replace external_war = 0 if participants_inter10 == "South Africa"
replace external_war = 0 if participants_inter11 == "South Africa"
replace external_war = 0 if participants_inter12 =="South Africa"
bysort year: egen tool = total(external_war) if South_Africa_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "South Africa"
drop tool external_war participant* South_Africa_neighbor
save "_South_Africa_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	South_Korea_neighbor  = 1 if country == "North Korea" 
replace external_war = 0 if participants_inter1 == "South Korea"
replace external_war = 0 if participants_inter2 == "South Korea"
replace external_war = 0 if participants_inter3 == "South Korea"
replace external_war = 0 if participants_inter4 == "South Korea"
replace external_war = 0 if participants_inter5 == "South Korea"
replace external_war = 0 if participants_inter6 == "South Korea"
replace external_war = 0 if participants_inter7 == "South Korea"
replace external_war = 0 if participants_inter8 == "South Korea"
replace external_war = 0 if participants_inter9 == "South Korea"
replace external_war = 0 if participants_inter10 == "South Korea"
replace external_war = 0 if participants_inter11 == "South Korea"
replace external_war = 0 if participants_inter12 =="South Korea"
bysort year: egen tool = total(external_war) if South_Korea_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "South Korea"
drop tool external_war participant* South_Korea_neighbor
save "_South_Korea_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Spain_neighbor  = 1 if country == "Andorra" | country == "France" | country == "Gibraltar" | country == "Morocco" | country == "Portugal" 
replace external_war = 0 if participants_inter1 == "Spain"
replace external_war = 0 if participants_inter2 == "Spain"
replace external_war = 0 if participants_inter3 == "Spain"
replace external_war = 0 if participants_inter4 == "Spain"
replace external_war = 0 if participants_inter5 == "Spain"
replace external_war = 0 if participants_inter6 == "Spain"
replace external_war = 0 if participants_inter7 == "Spain"
replace external_war = 0 if participants_inter8 == "Spain"
replace external_war = 0 if participants_inter9 == "Spain"
replace external_war = 0 if participants_inter10 == "Spain"
replace external_war = 0 if participants_inter11 == "Spain"
replace external_war = 0 if participants_inter12 =="Spain"
bysort year: egen tool = total(external_war) if Spain_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Spain"
drop tool external_war participant* Spain_neighbor
save "_Spain_neighbors.dta", replace

use "war_default_dataset_participants.dta", clear
gen	Sweden_neighbor  = 1 if country == "Finland" | country == "Norway" 
replace external_war = 0 if participants_inter1 == "Sweden"
replace external_war = 0 if participants_inter2 == "Sweden"
replace external_war = 0 if participants_inter3 == "Sweden"
replace external_war = 0 if participants_inter4 == "Sweden"
replace external_war = 0 if participants_inter5 == "Sweden"
replace external_war = 0 if participants_inter6 == "Sweden"
replace external_war = 0 if participants_inter7 == "Sweden"
replace external_war = 0 if participants_inter8 == "Sweden"
replace external_war = 0 if participants_inter9 == "Sweden"
replace external_war = 0 if participants_inter10 == "Sweden"
replace external_war = 0 if participants_inter11 == "Sweden"
replace external_war = 0 if participants_inter12 =="Sweden"
bysort year: egen tool = total(external_war) if Sweden_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Sweden"
drop tool external_war participant* Sweden_neighbor
save "_Sweden_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Switzerland_neighbor  = 1 if country == "Austria" | country == "France" | country == "Germany" | country == "Italy" | country == "Liechtenstein" 
replace external_war = 0 if participants_inter1 == "Switzerland"
replace external_war = 0 if participants_inter2 == "Switzerland"
replace external_war = 0 if participants_inter3 == "Switzerland"
replace external_war = 0 if participants_inter4 == "Switzerland"
replace external_war = 0 if participants_inter5 == "Switzerland"
replace external_war = 0 if participants_inter6 == "Switzerland"
replace external_war = 0 if participants_inter7 == "Switzerland"
replace external_war = 0 if participants_inter8 == "Switzerland"
replace external_war = 0 if participants_inter9 == "Switzerland"
replace external_war = 0 if participants_inter10 == "Switzerland"
replace external_war = 0 if participants_inter11 == "Switzerland"
replace external_war = 0 if participants_inter12 =="Switzerland"
bysort year: egen tool = total(external_war) if Switzerland_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Switzerland"
drop tool external_war participant* Switzerland_neighbor
save "_Switzerland_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Tajikistan_neighbor  = 1 if country == "Afghanistan" | country == "China" | country == "Kyrgyzstan" | country == "Uzbekistan" 
replace external_war = 0 if participants_inter1 == "Tajikistan"
replace external_war = 0 if participants_inter2 == "Tajikistan"
replace external_war = 0 if participants_inter3 == "Tajikistan"
replace external_war = 0 if participants_inter4 == "Tajikistan"
replace external_war = 0 if participants_inter5 == "Tajikistan"
replace external_war = 0 if participants_inter6 == "Tajikistan"
replace external_war = 0 if participants_inter7 == "Tajikistan"
replace external_war = 0 if participants_inter8 == "Tajikistan"
replace external_war = 0 if participants_inter9 == "Tajikistan"
replace external_war = 0 if participants_inter10 == "Tajikistan"
replace external_war = 0 if participants_inter11 == "Tajikistan"
replace external_war = 0 if participants_inter12 =="Tajikistan"
bysort year: egen tool = total(external_war) if Tajikistan_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Tajikistan"
drop tool external_war participant* Tajikistan_neighbor
save "_Tajikistan_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Thailand_neighbor  = 1 if country == "Cambodia" | country == "Laos" | country == "Malaysia" | country == "Myanmar" 
replace external_war = 0 if participants_inter1 == "Thailand"
replace external_war = 0 if participants_inter2 == "Thailand"
replace external_war = 0 if participants_inter3 == "Thailand"
replace external_war = 0 if participants_inter4 == "Thailand"
replace external_war = 0 if participants_inter5 == "Thailand"
replace external_war = 0 if participants_inter6 == "Thailand"
replace external_war = 0 if participants_inter7 == "Thailand"
replace external_war = 0 if participants_inter8 == "Thailand"
replace external_war = 0 if participants_inter9 == "Thailand"
replace external_war = 0 if participants_inter10 == "Thailand"
replace external_war = 0 if participants_inter11 == "Thailand"
replace external_war = 0 if participants_inter12 =="Thailand"
bysort year: egen tool = total(external_war) if Thailand_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Thailand"
drop tool external_war participant* Thailand_neighbor
save "_Thailand_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Tunisia_neighbor  = 1 if country == "Tunisia" | country == "Libya" 
replace external_war = 0 if participants_inter1 == "Tunisia"
replace external_war = 0 if participants_inter2 == "Tunisia"
replace external_war = 0 if participants_inter3 == "Tunisia"
replace external_war = 0 if participants_inter4 == "Tunisia"
replace external_war = 0 if participants_inter5 == "Tunisia"
replace external_war = 0 if participants_inter6 == "Tunisia"
replace external_war = 0 if participants_inter7 == "Tunisia"
replace external_war = 0 if participants_inter8 == "Tunisia"
replace external_war = 0 if participants_inter9 == "Tunisia"
replace external_war = 0 if participants_inter10 == "Tunisia"
replace external_war = 0 if participants_inter11 == "Tunisia"
replace external_war = 0 if participants_inter12 =="Tunisia"
bysort year: egen tool = total(external_war) if Tunisia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Tunisia"
drop tool external_war participant* Tunisia_neighbor
save "_Tunisia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Turkey_neighbor  = 1 if country == "Armenia" | country == "Azerbaijan" | country == "Bulgaria" | country == "Georgia" | country == "Greece" | country == "Iran" | country == "Iraq" | country == "Syria" 
replace external_war = 0 if participants_inter1 == "Turkey"
replace external_war = 0 if participants_inter2 == "Turkey"
replace external_war = 0 if participants_inter3 == "Turkey"
replace external_war = 0 if participants_inter4 == "Turkey"
replace external_war = 0 if participants_inter5 == "Turkey"
replace external_war = 0 if participants_inter6 == "Turkey"
replace external_war = 0 if participants_inter7 == "Turkey"
replace external_war = 0 if participants_inter8 == "Turkey"
replace external_war = 0 if participants_inter9 == "Turkey"
replace external_war = 0 if participants_inter10 == "Turkey"
replace external_war = 0 if participants_inter11 == "Turkey"
replace external_war = 0 if participants_inter12 =="Turkey"
bysort year: egen tool = total(external_war) if Turkey_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Turkey"
drop tool external_war participant* Turkey_neighbor
save "_Turkey_neighbors.dta", replace

use "war_default_dataset_participants.dta", clear
gen	Ukraine_neighbor  = 1 if country == "Belarus" | country == "Hungary" | country == "Moldova" | country == "Poland" | country == "Romania" | country == "Russia" | country == "Slovakia" 
replace external_war = 0 if participants_inter1 == "Ukraine"
replace external_war = 0 if participants_inter2 == "Ukraine"
replace external_war = 0 if participants_inter3 == "Ukraine"
replace external_war = 0 if participants_inter4 == "Ukraine"
replace external_war = 0 if participants_inter5 == "Ukraine"
replace external_war = 0 if participants_inter6 == "Ukraine"
replace external_war = 0 if participants_inter7 == "Ukraine"
replace external_war = 0 if participants_inter8 == "Ukraine"
replace external_war = 0 if participants_inter9 == "Ukraine"
replace external_war = 0 if participants_inter10 == "Ukraine"
replace external_war = 0 if participants_inter11 == "Ukraine"
replace external_war = 0 if participants_inter12 =="Ukraine"
bysort year: egen tool = total(external_war) if Ukraine_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Ukraine"
drop tool external_war participant* Ukraine_neighbor
save "_Ukraine_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	United_Kingdom_neighbor  = 1 if country == "Ireland" 
replace external_war = 0 if participants_inter1 == "United Kingdom"
replace external_war = 0 if participants_inter2 == "United Kingdom"
replace external_war = 0 if participants_inter3 == "United Kingdom"
replace external_war = 0 if participants_inter4 == "United Kingdom"
replace external_war = 0 if participants_inter5 == "United Kingdom"
replace external_war = 0 if participants_inter6 == "United Kingdom"
replace external_war = 0 if participants_inter7 == "United Kingdom"
replace external_war = 0 if participants_inter8 == "United Kingdom"
replace external_war = 0 if participants_inter9 == "United Kingdom"
replace external_war = 0 if participants_inter10 == "United Kingdom"
replace external_war = 0 if participants_inter11 == "United Kingdom"
replace external_war = 0 if participants_inter12 =="United Kingdom"
bysort year: egen tool = total(external_war) if United_Kingdom_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "United Kingdom"
drop tool external_war participant* United_Kingdom_neighbor
save "_United_Kingdom_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	USA_neighbor  = 1 if country == "Canada" | country == "Mexico" 
replace external_war = 0 if participants_inter1 == "United States of America"
replace external_war = 0 if participants_inter2 == "United States of America"
replace external_war = 0 if participants_inter3 == "United States of America"
replace external_war = 0 if participants_inter4 == "United States of America"
replace external_war = 0 if participants_inter5 == "United States of America"
replace external_war = 0 if participants_inter6 == "United States of America"
replace external_war = 0 if participants_inter7 == "United States of America"
replace external_war = 0 if participants_inter8 == "United States of America"
replace external_war = 0 if participants_inter9 == "United States of America"
replace external_war = 0 if participants_inter10 == "United States of America"
replace external_war = 0 if participants_inter11 == "United States of America"
replace external_war = 0 if participants_inter12 =="United States of America"
bysort year: egen tool = total(external_war) if USA_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "United States of America"
drop tool external_war participant* USA_neighbor
save "_United_States_of_America_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Uruguay_neighbor  = 1 if country == "Argentina" | country == "Brazil" 
replace external_war = 0 if participants_inter1 == "Uruguay"
replace external_war = 0 if participants_inter2 == "Uruguay"
replace external_war = 0 if participants_inter3 == "Uruguay"
replace external_war = 0 if participants_inter4 == "Uruguay"
replace external_war = 0 if participants_inter5 == "Uruguay"
replace external_war = 0 if participants_inter6 == "Uruguay"
replace external_war = 0 if participants_inter7 == "Uruguay"
replace external_war = 0 if participants_inter8 == "Uruguay"
replace external_war = 0 if participants_inter9 == "Uruguay"
replace external_war = 0 if participants_inter10 == "Uruguay"
replace external_war = 0 if participants_inter11 == "Uruguay"
replace external_war = 0 if participants_inter12 =="Uruguay"
bysort year: egen tool = total(external_war) if Uruguay_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Uruguay"
drop tool external_war participant* Uruguay_neighbor
save "_Uruguay_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Venezuela_neighbor  = 1 if country == "Brazil" | country == "Colombia" | country == "Guyana" 
replace external_war = 0 if participants_inter1 == "Venezuela"
replace external_war = 0 if participants_inter2 == "Venezuela"
replace external_war = 0 if participants_inter3 == "Venezuela"
replace external_war = 0 if participants_inter4 == "Venezuela"
replace external_war = 0 if participants_inter5 == "Venezuela"
replace external_war = 0 if participants_inter6 == "Venezuela"
replace external_war = 0 if participants_inter7 == "Venezuela"
replace external_war = 0 if participants_inter8 == "Venezuela"
replace external_war = 0 if participants_inter9 == "Venezuela"
replace external_war = 0 if participants_inter10 == "Venezuela"
replace external_war = 0 if participants_inter11 == "Venezuela"
replace external_war = 0 if participants_inter12 =="Venezuela"
bysort year: egen tool = total(external_war) if Venezuela_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Venezuela"
drop tool external_war participant* Venezuela_neighbor
save "_Venezuela_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Vietnam_neighbor  = 1 if country == "Cambodia" | country == "China" | country == "Laos" 
bysort year: egen tool = total(external_war) if Vietnam_neighbor == 1
replace external_war = 0 if participants_inter1 == "Vietnam"
replace external_war = 0 if participants_inter2 == "Vietnam"
replace external_war = 0 if participants_inter3 == "Vietnam"
replace external_war = 0 if participants_inter4 == "Vietnam"
replace external_war = 0 if participants_inter5 == "Vietnam"
replace external_war = 0 if participants_inter6 == "Vietnam"
replace external_war = 0 if participants_inter7 == "Vietnam"
replace external_war = 0 if participants_inter8 == "Vietnam"
replace external_war = 0 if participants_inter9 == "Vietnam"
replace external_war = 0 if participants_inter10 == "Vietnam"
replace external_war = 0 if participants_inter11 == "Vietnam"
replace external_war = 0 if participants_inter12 =="Vietnam"
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Vietnam"
drop tool external_war participant* Vietnam_neighbor
save "_Vietnam_neighbors.dta", replace



use "war_default_dataset_participants.dta", clear
gen	Yemen_neighbor  = 1 if country == "Oman" | country == "Saudi Arabia" 
replace external_war = 0 if participants_inter1 == "Yemen"
replace external_war = 0 if participants_inter2 == "Yemen"
replace external_war = 0 if participants_inter3 == "Yemen"
replace external_war = 0 if participants_inter4 == "Yemen"
replace external_war = 0 if participants_inter5 == "Yemen"
replace external_war = 0 if participants_inter6 == "Yemen"
replace external_war = 0 if participants_inter7 == "Yemen"
replace external_war = 0 if participants_inter8 == "Yemen"
replace external_war = 0 if participants_inter9 == "Yemen"
replace external_war = 0 if participants_inter10 == "Yemen"
replace external_war = 0 if participants_inter11 == "Yemen"
replace external_war = 0 if participants_inter12 =="Yemen"
bysort year: egen tool = total(external_war) if Yemen_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Yemen"
drop tool external_war participant* Yemen_neighbor
save "_Yemen_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Zambia_neighbor  = 1 if country == "Angola" | country == "Botswana" | country == "Democratic Republic of the Congo" | country == "Malawi" | country == "Mozambique" | country == "Namibia" | country == "Tanzania" | country == "Zimbabwe" 
replace external_war = 0 if participants_inter1 == "Zambia"
replace external_war = 0 if participants_inter2 == "Zambia"
replace external_war = 0 if participants_inter3 == "Zambia"
replace external_war = 0 if participants_inter4 == "Zambia"
replace external_war = 0 if participants_inter5 == "Zambia"
replace external_war = 0 if participants_inter6 == "Zambia"
replace external_war = 0 if participants_inter7 == "Zambia"
replace external_war = 0 if participants_inter8 == "Zambia"
replace external_war = 0 if participants_inter9 == "Zambia"
replace external_war = 0 if participants_inter10 == "Zambia"
replace external_war = 0 if participants_inter11 == "Zambia"
replace external_war = 0 if participants_inter12 =="Zambia"
bysort year: egen tool = total(external_war) if Zambia_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Zambia"
drop tool external_war participant* Zambia_neighbor
save "_Zambia_neighbors.dta", replace


use "war_default_dataset_participants.dta", clear
gen	Zimbabwe_neighbor  = 1 if country == "Botswana" | country == "Mozambique" | country == "South Africa" | country == "Zambia" 
replace external_war = 0 if participants_inter1 == "Zimbabwe"
replace external_war = 0 if participants_inter2 == "Zimbabwe"
replace external_war = 0 if participants_inter3 == "Zimbabwe"
replace external_war = 0 if participants_inter4 == "Zimbabwe"
replace external_war = 0 if participants_inter5 == "Zimbabwe"
replace external_war = 0 if participants_inter6 == "Zimbabwe"
replace external_war = 0 if participants_inter7 == "Zimbabwe"
replace external_war = 0 if participants_inter8 == "Zimbabwe"
replace external_war = 0 if participants_inter9 == "Zimbabwe"
replace external_war = 0 if participants_inter10 == "Zimbabwe"
replace external_war = 0 if participants_inter11 == "Zimbabwe"
replace external_war = 0 if participants_inter12 =="Zimbabwe"
bysort year: egen tool = total(external_war) if Zimbabwe_neighbor == 1
bysort year: egen n_neighbors_at_war = max(tool)
keep if country == "Zimbabwe"
drop tool external_war participant* Zimbabwe_neighbor
save "_Zimbabwe_neighbors.dta", replace
						
						
*** Merge all country_neighbor files													
append using _Albania_neighbors.dta
append using _Argentina_neighbors.dta
append using _Armenia_neighbors.dta
append using _Australia_neighbors.dta
append using _Austria_neighbors.dta
append using _Azerbaijan_neighbors.dta
append using _Bangladesh_neighbors.dta
append using _Belarus_neighbors.dta
append using _Belgium_neighbors.dta
append using _Bhutan_neighbors.dta
append using _Bolivia_neighbors.dta
append using _Bosnia_and_Herzegovina_neighbors.dta
append using _Brazil_neighbors.dta
append using _Bulgaria_neighbors.dta
append using _Burundi_neighbors.dta
append using _Cambodia_neighbors.dta
append using _Canada_neighbors.dta
append using _Chad_neighbors.dta
append using _Chile_neighbors.dta
append using _China_neighbors.dta
append using _Colombia_neighbors.dta
append using _Congo_neighbors.dta
append using _Costa_Rica_neighbors.dta
append using _Croatia_neighbors.dta
append using _Cyprus_neighbors.dta
append using _Czech_Republic_neighbors.dta
append using _Democratic_Republic_Congo_neighbors.dta
append using _Denmark_neighbors.dta
append using _Dominican_Republic_neighbors.dta
append using _Ecuador_neighbors.dta
append using _Egypt_neighbors.dta
append using _El_Salvador_neighbors.dta
append using _Estonia_neighbors.dta
append using _Ethiopia_neighbors.dta
append using _Finland_neighbors.dta
append using _France_neighbors.dta
append using _Georgia_neighbors.dta
append using _Germany_neighbors.dta
append using _Greece_neighbors.dta
append using _Guatemala_neighbors.dta
append using _Guinea_neighbors.dta
append using _Honduras_neighbors.dta
append using _Hungary_neighbors.dta
append using _India_neighbors.dta
append using _Indonesia_neighbors.dta
append using _Iran_neighbors.dta
append using _Ireland_neighbors.dta
append using _Israel_neighbors.dta
append using _Italy_neighbors.dta
append using _Ivory_Coast_neighbors.dta
append using _Kazakhstan_neighbors.dta
append using _Kenya_neighbors.dta
append using _Latvia_neighbors.dta
append using _Lebanon_neighbors.dta
append using _Lesotho_neighbors.dta
append using _Lithuania_neighbors.dta
append using _Macedonia_neighbors.dta
append using _Malaysia_neighbors.dta
append using _Mali_neighbors.dta
append using _Mexico_neighbors.dta
append using _Moldova_neighbors.dta
append using _Mongolia_neighbors.dta
append using _Morocco_neighbors.dta
append using _Myanmar_neighbors.dta
append using _Namibia_neighbors.dta
append using _Nepal_neighbors.dta
append using _Netherlands_neighbors.dta
append using _Nicaragua_neighbors.dta
append using _Nigeria_neighbors.dta
append using _Norway_neighbors.dta
append using _Pakistan_neighbors.dta
append using _Panama_neighbors.dta
append using _Paraguay_neighbors.dta
append using _Peru_neighbors.dta
append using _Poland_neighbors.dta
append using _Portugal_neighbors.dta
append using _Romania_neighbors.dta
append using _Russia_neighbors.dta
append using _Rwanda_neighbors.dta
append using _Senegal_neighbors.dta
append using _Slovakia_neighbors.dta
append using _Slovenia_neighbors.dta
append using _South_Africa_neighbors.dta
append using _South_Korea_neighbors.dta
append using _Spain_neighbors.dta
append using _Sweden_neighbors.dta
append using _Switzerland_neighbors.dta
append using _Tajikistan_neighbors.dta
append using _Thailand_neighbors.dta
append using _Tunisia_neighbors.dta
append using _Turkey_neighbors.dta
append using _Ukraine_neighbors.dta
append using _United_Kingdom_neighbors.dta
append using _United_States_of_America_neighbors.dta
append using _Uruguay_neighbors.dta
append using _Venezuela_neighbors.dta
append using _Vietnam_neighbors.dta
append using _Yemen_neighbors.dta
append using _Zambia_neighbors.dta

sort country year

save "neighbors_at_war.dta", replace

***********************************************************
* Merge war_neighbor files with main data
***********************************************************

use "war_default_dataset_participants.dta", clear

merge 1:1 country year using "neighbors_at_war.dta"

* Islands do not enter the previous dataset.
	replace n_neighbors_at_war = 0 if _merge != 3
	drop _merge

* Sudden-stop years
gen freeze_4y = 0 
replace freeze_4y = 1 if year >=1825 & year<=1829
replace freeze_4y = 1 if year >=1837 & year<= 1844
replace freeze_4y = 1 if year >=1847 & year<= 1854
replace freeze_4y = 1 if year >=1857	& year<= 1861
replace freeze_4y = 1 if year >=1865  & year<=1871
replace freeze_4y = 1 if year >=1890 & year<= 1894

*** Add 1910, a stock market crisis
	replace freeze_4y = 1 if year >=1910 & year<= 1914
*** Add 1873 crisis, not considered in Reinhart and Rogoff. 
	replace freeze_4y = 1 if year >=1873 & year<= 1877

* War while credit flows
bysort cowcode: gen neig_war_and_flow_uk_4y = 0 if n_neighbors_at_war == 0
bysort cowcode: replace neig_war_and_flow_uk_4y = 1 if (n_neighbors_at_war > 0 & n_neighbors_at_war<10) & freeze_4y == 0
bysort cowcode: egen total_neig_war_and_flow_uk_4y = total(neig_war_and_flow_uk_4y)
	
* War while credit stops
bysort cowcode: gen neig_war_and_stop_uk_4y = 0 if n_neighbors_at_war == 0
bysort cowcode: replace neig_war_and_stop_uk_4y = 1 if (n_neighbors_at_war > 0 & n_neighbors_at_war<10) & freeze_4y == 1
bysort cowcode: egen total_neig_war_and_stop_uk_4y = total(neig_war_and_stop_uk_4y)


***********************************************************
* Merge Sudden-stop + War Neighbor Data with Controls
***********************************************************

bysort cowcode: gen count = _n
keep if count == 1

keep country cowcode total_neig_war_and_stop_uk_4y total_neig_war_and_flow_uk_4y

merge 1:1 cowcode using "all_controls.dta"
drop _merge

save "data_for_analysis_reduced_form.dta", replace

log close